MATLAB: Determine the Z value of a 3D region for a given set of co-ordinates

3d matrixinterpolationMATLAB

Hi,
I have a 3D matrix and I want to be able to determine the Z value for a given set of X and Y co-ordinates. The X and Y value that i have in mind is not on the regular grid, so I think i will need interpolation to find the Z value.
Can anyone tell me how this can be done ?
Cheers,

Best Answer

the function interp2() will work. The example in the help/documentation is
[X,Y,V] = peaks(10); [Xq,Yq] = meshgrid(-3:.1:3,-3:.1:3);
Vq = interp2(X,Y,V,Xq,Yq); mesh(Xq,Yq,Vq)
As you can see in the interp2 function it has the original X,Y,Z (or in this case V) and then the user defines the Xq and Yq points that are not on the original grid. the Xq and Yq can be a single XY pair to get the interpolated Z value.
Related Question