Help on interp3 function (meshgrid compatibility error on input data)

2 次查看(过去 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

回答(1 个)

Walter Roberson
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
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 );

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by