MATLAB Answers


interp and interp3 give different size arrays

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);
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);
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);
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?


Sign in to comment.

1 Answer

Answer by ANKUR KUMAR on 9 Oct 2018
 Accepted Answer

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
%finer points
Xr =1:0.5:90; %defining the finer resolution points.
Yr =1:0.5:100;
Zr= 1:0.5:100;


x0 = 1:10;
y0 = 1:20;
z0 = 1:30;
ans =
20 10 30
data1 should be 20x10x30. if your data is in 10x20x30, then firstly permute the matrix and switch the dimension.
ans =
20 10 30
Yes I realized I was able to do so after making a finer meshgrid first as well

Sign in to comment.