We will use the following data:
x = 1:5:50;
y = randi([-10 10],1,10);
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');
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');
next interpolation,
z_y = interp1(x,y,z, 'next');
previous interpolation,
z_y = interp1(x,y,z, 'previous');
Shape-preserving piecewise cubic interpolation,
z_y = interp1(x,y,z, 'pchip');
cubic convolution, z_y = interp1(x,y,z, 'v5cubic');
and spline interpolation
z_y = interp1(x,y,z, 'spline');
Hereby are nearst, next and previous interpolation piecewise constant interpolations.