interp1

One dimensional interpolation.

Syntax

yi = interp1(x,y,xi)

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

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

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

Inputs

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

Outputs

yi
The interpolated y values corresponding to xi.

Examples

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

Comments

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

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