MATLAB Language Piecewise interpolation 2 dimensional


Example

We initialize the data:

[X,Y] = meshgrid(1:2:10);
Z = X.*cos(Y) - Y.*sin(X);

The surface looks like the following. interp2-data

Now we set the points where we want to interpolate:

[Vx,Vy] = meshgrid(1:0.25:10); 

We now can perform nearest interpolation,

Vz = interp2(X,Y,Z,Vx,Vy,'nearest');

interp2-nearest

linear interpolation,

Vz = interp2(X,Y,Z,Vx,Vy,'linear');

interp2-linear

cubic interpolation

Vz = interp2(X,Y,Z,Vx,Vy,'cubic');

or spline interpolation:

Vz = interp2(X,Y,Z,Vx,Vy,'spline');

interp2-spline