yy = spline(x,Y,xx) uses a
cubic spline interpolation to find yy, the values
of the underlying function Y at the values of the
interpolant xx. For the interpolation, the independent
variable is assumed to be the final dimension of Y with
the breakpoints defined by x.

The sizes of xx and yy are
related as follows:

If Y is a scalar or vector, yy has
the same size as xx.

If Y is an array that is not a
vector,

If xx is a scalar or vector, size(yy) equals [d1,
d2, ..., dk, length(xx)].

If xx is an array of size [m1,m2,...,mj], size(yy) equals [d1,d2,...,dk,m1,m2,...,mj].

pp = spline(x,Y) returns
the piecewise polynomial form of the cubic spline interpolant for
later use with ppval and the spline utility unmkpp. x must
be a vector. Y can be a scalar, a vector, or an
array of any dimension, subject to the following conditions:

If x and Y are vectors of the same size, the not-a-knot
end conditions are used.

If x or Y is a scalar, it is expanded to have the
same length as the other and the not-a-knot end conditions are used.
(See Exceptions(1) below).

If Y is a vector that contains two more values than
x has entries, the first and last value in Y are used as the endslopes
for the cubic spline. (See Exceptions (2) below.)

Exceptions

If Y is
a vector that contains two more values than x has
entries, the first and last value in Y are used
as the endslopes for the cubic spline. If Y is
a vector, this means

f(x) = Y(2:end-1)

df(min(x)) = Y(1)

df(max(x)) = Y(end)

If Y is
a matrix or an N-dimensional array with size(Y,N) equal
to length(x)+2, the following hold:

f(x(j)) matches the value Y(:,...,:,j+1) for j=1:length(x)

Df(min(x)) matches Y(:,:,...:,1)

Df(max(x)) matches Y(:,:,...:,end)

Note
You can also perform spline interpolation using the interp1 function with the command interp1(x,y,xx,'spline').
Note that while spline performs interpolation on
rows of an input matrix, interp1 performs interpolation
on columns of an input matrix.

This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. Zero slopes at the ends of an interpolant to the values of a certain distribution are enforced.

x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');

generate the plot of a circle, with the five data points y(:,2),...,y(:,6) marked with o's. Note that this y contains two more values (i.e., two more columns) than does x, hence y(:,1) and y(:,end) are used as endslopes.

The following code generates sine and cosine curves, then samples the splines over a finer mesh.

x = 0:.25:1;
Y = [sin(x); cos(x)];
xx = 0:.1:1;
YY = spline(x,Y,xx);
plot(x,Y(1,:),'o',xx,YY(1,:),'-')
hold on
plot(x,Y(2,:),'o',xx,YY(2,:),':')
hold off

A tridiagonal linear system (with, possibly, several right sides)
is being solved for the information needed to describe the coefficients
of the various cubic polynomials which make up the interpolating spline. spline uses
the functions ppval, mkpp,
and unmkpp. These routines form a small suite
of functions for working with piecewise polynomials. For access to
more advanced features, see the interp1 reference
page, the command-line help for these functions, and the Curve Fitting Toolbox™ spline
functions.

References

[1] de Boor, C., A Practical Guide
to Splines, Springer-Verlag, 1978.