MATLAB Answers

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

1 ビュー (過去 30 日間)
AP
AP 2013 年 1 月 2 日
コメント済み: chris crowley 2017 年 2 月 8 日
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 );

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by