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

조회 수: 3 (최근 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 );

댓글을 달려면 로그인하십시오.

카테고리

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