MATLAB Language Piecewise interpolation 1 dimensional


Example

We will use the following data:

x = 1:5:50;
y = randi([-10 10],1,10);

interp1-data

Hereby x and y are the coordinates of the data points and z are the points we need information about.

z = 0:0.25:50;

One way to find the y-values of z is piecewise linear interpolation.

z_y = interp1(x,y,z,'linear');

interp1-linear

Hereby one calculates the line between two adjacent points and gets z_y by assuming that the point would be an element of those lines.

interp1 provides other options too like nearest interpolation,

z_y = interp1(x,y,z, 'nearest');

interp1-nearst

next interpolation,

z_y = interp1(x,y,z, 'next');

interp1-next

previous interpolation,

z_y = interp1(x,y,z, 'previous');

interp1-previous

Shape-preserving piecewise cubic interpolation,

z_y = interp1(x,y,z, 'pchip');

interp1-pchip

cubic convolution, z_y = interp1(x,y,z, 'v5cubic');

interp1-v5cubic

and spline interpolation

z_y = interp1(x,y,z, 'spline');

interp1-spline

Hereby are nearst, next and previous interpolation piecewise constant interpolations.