MATLAB Answers

interp and interp3 give different size arrays

2 views (last 30 days)
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?

Accepted Answer

ANKUR KUMAR
ANKUR KUMAR on 9 Oct 2018
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 Comments
Nathaniel H Werner
Nathaniel H Werner on 9 Oct 2018
Yes I realized I was able to do so after making a finer meshgrid first as well

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!