One dimensional interpolation.


yi = interp1(x,y,xi)

yi = interp1(x,y,xi,method)

yi = interp1(x,y,xi,extrap)

yi = interp1(x,y,xi,method,extrap)


The known points with which to interpolate.
Type: double
Dimension: vector
The domain points at which to interpolate.
Type: double
Dimension: vector
The available options are:
Returns the linear interpolation from the nearest neighbors.
Returns shape preserving piece-wise cubic Hermite interpolation.
Returns the cubic spline interpolation.
Type: string
The available options are:
Allows extrapolation beyond the interval.
Does not allow extrapolation (default).
Type: string


The interpolated y values corresponding to xi.


With 'linear' method and no extrapolation:

x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [1.5,2.5,3.5,4.5];
yi = interp1(x,y,xi,'linear')
yi = [Matrix] 1 x 4
2.50000  6.50000  12.50000  20.50000

With 'linear' method and extrapolation:

x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [0.5,1.5,2.5,3.5,4.5,5.5];
yi = interp1(x,y,xi,'linear','extrap')
yi = [Matrix] 1 x 6
-0.50000  2.50000  6.50000  12.50000  20.50000  29.50000

With 'spline' method and no extrapolation:

x = [1,2,3,4,5];
y = [1,4,9,16,25];
xi = [1.5,2.5,3.5,4.5];
yi = interp1(x,y,xi,'spline')
yi = [Matrix] 1 x 4
2.25000  6.25000  12.25000  20.25000


When y is a matrix, the function operates along the first dimension, which is the column dimension in the 2D case. This convention is the opposite of spline.

For the 'linear' method, duplicate x values are allowed if the vector is sorted, indicating a discontinuous function. The function is treated as right-continuous if x is in ascending order, and left-continuous if descending. More than two identical x values are not allowed.

For methods other than 'linear', x values must be unique.

The 'spline' method uses the not-a-knot cubic spline.