spline

Interpolate (x,y) data with a cubic spline.

Syntax

yi = spline(x,y,xi)

Inputs

x,y
The known points with which to create a spline.
Type: double
Dimension: vector
xi
The domain points at which to interpolate.
Type: double
Dimension: vector

Outputs

yi
The interpolated y values corresponding to xi.

Example

Interpolate a sine wave.

x = [0:0.2:1]*pi;
y = sin(x);
xi = [0.1:0.2:0.9]*pi;
yi = spline(x,y,xi)
yi = [Matrix] 1 x 5
0.31155  0.80789  0.99993  0.80789  0.31155

Comments

The not-a-knot spline is evaluated when the length of y equals the length of x.

The clamped spline is evaluated when the length of y equals the length of x plus 2. The first and last elements of y are the derivatives at the first and last values of x, so that the indices of the y values are offset by one from the indices of their paired x values.

When y is a matrix, the function operates along the last dimension, which is the row dimension in the 2D case. This is the opposite convention from interp1.