Help on interp3 function (meshgrid compatibility error on input data)
1 次查看(过去 30 天)
显示 更早的评论
Dear All,
I am trying to use interp3 for my data which can be found at http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid:73338. The file is about 7MB. The data is distributed over an ordered Cartesian grid with uniform intervals. I can successfully use stream3 by adjusting the data for meshgrid compatibility according to the following code using permute function. It works fine. However, when I want to do interpolation, I get an error which says the input data is not a valid meshgrid.
x = permute(x , [2 1 3]);
y = permute(y , [2 1 3]);
z = permute(z , [2 1 3]);
u = permute(u , [2 1 3]);
v = permute(v , [2 1 3]);
w = permute(w , [2 1 3]);
InOut = permute(InOut , [2 1 3]);
[ sx, sy, sz ] = meshgrid( -1:1:1, -1:1:1, -1:1:1 );
vertices = stream3( x, y, z, u, v, w, sx(:), sy(:), sz(:) );
val = interp3( x, y, z, InOut, 0, 0, 0 );
The above code stops at the line where I do the interpolation. Could someone help me?
Thanks, Ahmad
0 个评论
回答(1 个)
Walter Roberson
2013-1-2
Although error messages from the interp functions complain about needing meshgrid format, I find that in practice it is ndgrid() format that they need.
1 个评论
chris crowley
2017-2-8
I have the same issue as Ahmad above and when I use either meshgrid or ndgrid for both the input and the output I still get this error.
using his data:
x = permute(x , [2 1 3]);
y = permute(y , [2 1 3]);
z = permute(z , [2 1 3]);
u = permute(u , [2 1 3]);
v = permute(v , [2 1 3]);
w = permute(w , [2 1 3]);
InOut = permute(InOut , [2 1 3]);
[ xnew, ynew, znew ] = ndgrid( min(x(1,:,1)):(max(x(1,:,1))-min(x(1,:,1)))/length(x(1,:,1)):max(x(1,:,1)),...
min(y(:,1,1)):(max(y(:,1,1))-min(y(:,1,1)))/length(y(:,1,1)):max(y(:,1,1)),...
min(z(1,1,:)):(max(z(1,1,:))-min(z(1,1,:)))/length(z(1,1,:)):max(z(1,1,:)) );
[ sx, sy, sz ] = ndgrid( -1:1:1, -1:1:1, -1:1:1 );
val = interp3( xnew, ynew, znew, InOut, sx, sy, sz );
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!