Does a cubic spline interpolation of a data set.
Syntax |
Description |
---|---|
out = spline(Ex,xold,xnew); |
"not-a-knot" cubic spline interpolation of a 1D function.
The points in xnew do not have to be within the bounds of xold. |
spline(Ex,xold,xnew,[derivMin; derivMax]); |
"clamped cubic spline" interpolation of a 1D function.
|
Note: "spline" script has been modified for versions of 2020 R2 or higher. To recover the result from previous versions, users will need to explicitly use the "clamped cubic spline". eg, define
derivMin = (Ex(2)-Ex(1))/(xold(2)-xold(1));
derivMax = (Ex(end)-Ex(end-1))/(xold(end)-xold(end-1));
Example
Resample Ex at xnew using cubic spline and linear interpolation methods. Note that xnew is outside the bounds of xold.
xold=linspace(0,10,7); Ex=sin(xold); xnew=linspace(-1,9,25); # defining a new x vector Exnew=interp(Ex,xold,xnew); # interpolating the new data set Exnew2=spline(Ex,xold,xnew); # smoothing plotxy(xold,Ex,xnew,Exnew,xnew,Exnew2,"x","y",""); legend("old data", "interp", "Spline");
The example code will generate the plot below. The figure shows the difference between the linear and cubic spline interpolation techniques.
See Also