interp and interp3 give different size arrays

조회 수: 2 (최근 30일)
Nathaniel H Werner
Nathaniel H Werner 2018년 10월 9일
댓글: Nathaniel H Werner 2018년 10월 9일
If I start with the following two arrays
x0 = 1:100;
y0 = 1:80;
z0 = 1:100;
and I make a mesh grid with them
[X0, Y0, Z0] = meshgrid(x0, y0, z0);
Now if I plug in x0 into interp and use a factor of 2 I get
xw = interp(x0,2);
size(xw)
ans =
1 200
Doing the same but with interp3 I expect to get a 160 x 200 x 200 array instead I get
Xw = interp3(X0,2);
size(Xw)
ans =
317 397 397
which is just 3 less than an additional factor of 2.
Why is that and how can I correct that?
I have some flow data that is in an N x M x P array A
M = length(x0);
N = length(y0);
P = length(z0);
size(A)
ans =
80 100 100
using these numbers. I want to interpolate the 3D data onto a finer mesh rN x rM x rP where r is some integer >= 2. Can I do this with interp3 or do I need to use something else?

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2018년 10월 9일
x0 = 1:100;
y0 = 1:90;
z0 = 1:100;
data1=randi(10,90,100,100); %defining data over coarser resolution
dimension of data1 should be dim(y0)x dim(x0)x dim(z0). See the comment to this answer for more clarification
[x0_mesh,y0_mesh,z0_mesh]=meshgrid(x0,y0,z0);
%finer points
Xr =1:0.5:90; %defining the finer resolution points.
Yr =1:0.5:100;
Zr= 1:0.5:100;
[Xr_mesh,Yr_mesh,Zr_mesh]=meshgrid(Xr,Yr,Zr);
data1_finer_grid=interp3(x0_mesh,y0_mesh,z0_mesh,data1,Xr_mesh,Yr_mesh,Zr_mesh);
size(data1)
size(data1_finer_grid)
  댓글 수: 2
ANKUR KUMAR
ANKUR KUMAR 2018년 10월 9일
x0 = 1:10;
y0 = 1:20;
z0 = 1:30;
data1=rand(20,10,30);
size(data1)
ans =
20 10 30
data1 should be 20x10x30. if your data is in 10x20x30, then firstly permute the matrix and switch the dimension.
data2=rand(10,20,30)
data2=permute(data2,[2,1,3])
size(data2)
ans =
20 10 30
Nathaniel H Werner
Nathaniel H Werner 2018년 10월 9일
Yes I realized I was able to do so after making a finer meshgrid first as well

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by