MATLAB: Cross Product multi Dim data

cross product

I have u1 v1 w1(velocity components) volumetric data. Size of u1 is NxNxN (N is 100) and same is true frol v1 and w1.
I have one more case of u2, v2, w2, each one of size NxNxN. both these data sets are obtained from TriScatteredInterp and meshgrid. Basically i plotted streamlines for these two cases and now i want to see how much deviation is there between these streamlines (from case 1 to 2.). I need to find the angle between them at the points given by meshgrid. But cross product wont work (A and B must have at least one dimension of length 3.).. any suggestion ?? Thanks a lot

Best Answer

Actually you can use matlab's 'cross' function.
A = cat(4,u1,v1,w1); % Combine the three components in the 4th dimension
B = cat(4,u2,v2,w2); % Ditto
C = cross(A,B,4); % Take the cross products there.
ang = atan2(sqrt(dot(C,C,4)),dot(A,B,4));
This last is taking atan2(norm(cross products),dot products), which is the accurate way of finding angles. The result should be a three dimensional NxNxN array of angles. The angles can range from 0 to pi radians.