Confusion with interp3 and interpn

조회 수: 2 (최근 30일)
Tahariet Sharon
Tahariet Sharon 2020년 4월 24일
편집: Tahariet Sharon 2020년 5월 26일
Hi,
According to my teacher, "for a matrix indexed as [M, N, P], the axis variables must be given in the order N, M, P" in relation to the swaping of variables at the interp3 line:
[X, Y, Z] = size(data);
ts= [20 30 20]
[x, y, z] = ndgrid((1:X)/X, (1:Y)/Y, (1:Z)/Z);
[x2, y2, z2] = ndgrid((1:ts(1))/(ts(1)), (1:ts(2))/(ts(2)), (1:ts(3))/(ts(3)));
test1= interp3(y, x, z, data, y2, x2, z2, 'linear');
However, I couldn't find this info on the function's page, nor it makes any sense to me (even though the computation seems correct!).
Any help welcome, thank you,
TS
  댓글 수: 5
Tahariet Sharon
Tahariet Sharon 2020년 5월 25일
편집: Tahariet Sharon 2020년 5월 25일
Yes, of course I did, but it outputs an error:
Error using interp3 (line 150)
Input grid is not a valid MESHGRID.
darova
darova 2020년 5월 25일
Maybe it's the answer on your question

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

채택된 답변

Steven Lord
Steven Lord 2020년 4월 24일
I think reading through this documentation page may be of use to you, especially the examples in the Grid Representation section.
  댓글 수: 1
Tahariet Sharon
Tahariet Sharon 2020년 5월 25일
Still, Why the order of variables should be "y,x,z"?

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

추가 답변 (1개)

darova
darova 2020년 5월 25일
here is an example
[x,y] = meshgrid(1:5);
z = x.^2 + y.^2/2;
[x1,y1] = meshgrid(1:0.5:5);
z1 = interp2(x,y,z,x1,y1); % standart interpolation
z2 = interp2(y',x',z,y1',x1'); % interpolation y x
surf(x,y,z,'facecolor','none')
hold on
plot3(x1(:),y1(:),z1(:),'.r')
plot3(x1(:),y1(:),z2(:),'ob')
hold off
legend('original surface',...
'standard interpolation',...
'y x interpolation','location','north')
axis vis3d
  댓글 수: 2
Tahariet Sharon
Tahariet Sharon 2020년 5월 26일
Thanks, however, you are using interp2, and not interp3. Do the same with interp3 and you will get an error, I would expect. See here: https://groups.google.com/forum/#!topic/comp.soft-sys.matlab/xlinA3xsxT8 "Does interp3 switch X and Y".

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

카테고리

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