# Interpolating 3D Array non-monotonic data in MatLab

I am working on creating a program for simulations where three variables are parametrized, and we modify one parameter while keeping the other two constant. An example array looks like this when outputted by MatLab:

    dim3arr(:,:,1) =

0.8000    0.9000    1.0000    1.1000    1.2000
0         0         0         0         0
0.5000    0.5000    0.5000    0.5000    0.5000

dim3arr(:,:,2) =

0.8000    0.8000    0.8000    0.8000    0.8000
0   10.0000   20.0000   35.0000   60.0000
0.5000    0.5000    0.5000    0.5000    0.5000

dim3arr(:,:,3) =

0.8000    0.8000    0.8000    0.8000    0.8000
0         0         0         0         0
0.5000    0.6000    0.8000    1.1000    1.5000


I am trying to figure out how to interpolate between points in the array. MatLab's documentation for interpolating on N-dimensional arrays seems to assume that the data is monotonically increasing. How would I get MatLab to interpolate the data?

• Do you need to interpolate the values where in the matrix? I think that you can do this with interp3 – nicoguaro Feb 13 '15 at 23:38

It's not the data that needs to be monotonic, it's the coordinates (your three variables) that must be monotonically increasing. As suggested by @nicoguaro in his comment, interp3 should work fine for this as long as you have things ordered properly.

If you mean that your variables are non-monotonic then you will simply have to reorder things. Calling your variables x, y, and z and assuming that they correspond to dimensions 1, 2, and 3 respectively of dim3arr you could do this via:

[x, Ix]=sort(x);
[y, Iy]=sort(y);
[z, Iz]=sort(z);
dim3arr = dim3arr(Ix,:,:);
dim3arr = dim3arr(:,Iy,:);
dim3arr = dim3arr(:,:,Iz);


Or, just make sure x, y, z are monotonic before using them to generate dim3arr.