I have the following two vector fields:
>> orient
orient =
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
>> distance
distance =
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
and I need to take the cross product of pairwise elements i.e.
b = (cross(orient{1,1},distance{1,1}) + cross(orient{1,2},distance{1,2})..... and so on
and then reshape to match the dimensions of distance and orient.
Can I do this without using a for loop?
and what about if I have
orient{1,1} =
[1x3 double]
distance =
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double]
how do I do
sum1 = (cross(orient{1,1},distance{1,1}) + cross(orient{1,1},distance{1,2}) +…)
sum2 = (cross(orient{1,2},distance{1,1}) + cross(orient{1,2},distance{1,2}) +…)
where each ‘sum’ is just an iteration of a single orient element, crossed with all the elements of distance, and then those cross products are summed. I would then have:
mastersum = sum1 sum2 sum3
sum4 sum5 sum6
sum6 sum8 sum9
where
sum1 =
[1x3 double]
Am I just putting this in a confusing way?
You’ll need to use
cellfunto traverse the cell arrays without afor-loop.For two vector fields (two cell arrays), you should do:
A similar procedure for single cell from
orient, sayorient{1, 2}, would be:To get the result for all vectors from
orientwithout aforloop, do instead:Now
Uis also a cell array (of the same dimensions asorient):U{1, 1}has the sum of crosses fororient{1, 1},U{1, 2}fororient{1, 2}, and so on…