Documentation |
On this page… |
---|
Interpolation is a process for estimating values that lie between known data points.
Interpolant Methods
Method | Description |
---|---|
Linear | Linear interpolation. This method fits a different linear polynomial between each pair of data points for curves, or between sets of three points for surfaces. |
Nearest neighbor | Nearest neighbor interpolation. This method sets the value of an interpolated point to the value of the nearest data point. Therefore, this method does not generate any new data points. |
Cubic spline | Cubic spline interpolation. This method fits a different cubic polynomial between each pair of data points for curves, or between sets of three points for surfaces. |
Shape-preserving | Piecewise cubic Hermite interpolation (PCHIP). This method preserves monotonicity and the shape of the data. For curves only. |
Biharmonic (v4) | MATLAB^{®} 4 griddata method. For surfaces only. |
Thin-plate spline | Thin-plate spline interpolation. This method fits smooth surfaces that also extrapolate well. For surfaces only. |
For surfaces, the Interpolant fit type uses the MATLAB scatteredInterpolant function for linear and nearest methods, and the MATLAB griddata function for cubic and biharmonic methods. The thin-plate spline method uses the tpaps function.
The type of interpolant to use depends on the characteristics of the data being fit, the required smoothness of the curve, speed considerations, post-fit analysis requirements, and so on. The linear and nearest neighbor methods are fast, but the resulting curves are not very smooth. The cubic spline and shape-preserving and v4 methods are slower, but the resulting curves are very smooth.
For example, the nuclear reaction data from the carbon12alpha.mat file is shown here with a nearest neighbor interpolant fit and a shape-preserving (PCHIP) interpolant fit. Clearly, the nearest neighbor interpolant does not follow the data as well as the shape-preserving interpolant. The difference between these two fits can be important if you are interpolating. However, if you want to integrate the data to get a sense of the total strength of the reaction, then both fits provide nearly identical answers for reasonable integration bin widths.
Note Goodness-of-fit statistics, prediction bounds, and weights are not defined for interpolants. Additionally, the fit residuals are always 0 (within computer precision) because interpolants pass through the data points. |
Interpolants are defined as piecewise polynomials because the fitted curve is constructed from many "pieces" (except for Biharmonic for surfaces which is a radial basis function interpolant). For cubic spline and PCHIP interpolation, each piece is described by four coefficients, which the toolbox calculates using a cubic (third-degree) polynomial.
Refer to the spline function for more information about cubic spline interpolation.
Refer to the pchip function for more information about shape-preserving interpolation, and for a comparison of the two methods.
Refer to the scatteredInterpolant, griddata, and tpaps functions for more information about surface interpolation.
It is possible to fit a single "global" polynomial interpolant to data, with a degree one less than the number of data points. However, such a fit can have wildly erratic behavior between data points. In contrast, the piecewise polynomials described here always produce a well-behaved fit, so they are more flexible than parametric polynomials and can be effectively used for a wider range of data sets.
In the Curve Fitting app, select Interpolant from the model type list.
The Interpolant fit category fits an interpolating curve or surface that passes through every data point. For surfaces, the Interpolant fit type uses the MATLAB scatteredInterpolant function for linear and nearest methods, the MATLAB griddata function for cubic and biharmonic methods, and the tpaps function for thin-plate spline interpolation.
The settings are shown here.
You can specify the Method setting: Nearest neighbor, Linear, Cubic, Shape-preserving (PCHIP) (for curves), Biharmonic (v4) (for surfaces) or Thin-plate spline (for surfaces). For details, see Interpolation Methods.
Tip If you are fitting a surface and your input variables have different scales, turn the Center and scale option on and off to see the difference in the surface fit. Normalizing the inputs can strongly influence the results of the triangle-based (i.e., piecewise Linear and Cubic interpolation) and Nearest neighbor surface interpolation methods. |
For surfaces, try thin-plate splines when you require both smooth surface interpolation and good extrapolation properties.
Specify the interpolant model method when you call the fit function using one of these options.
Type | Interpolant Fitting Method | Description |
---|---|---|
Curves and Surfaces | linearinterp | Linear interpolation |
nearestinterp | Nearest neighbor interpolation | |
cubicinterp | Cubic spline interpolation | |
Curves only | pchipinterp | Shape-preserving piecewise cubic Hermite (pchip) interpolation |
Surfaces only | biharmonicinterp | Biharmonic (MATLAB griddata) interpolation |
thinplateinterp | Thin-plate spline interpolation |
There are no additional fit option parameters for any of the interpolant methods.
For example, to load some data and fit a linear interpolant model:
load census; f = fit(cdate, pop, 'linearinterp') plot(f,cdate,pop)
To create and compare nearest neighbor and pchip interpolant fits on a plot:
load carbon12alpha f1 = fit(angle, counts, 'nearestinterp') f2 = fit(angle, counts, 'pchip') p1 = plot(f1, angle, counts) xlim( [min(angle), max(angle)]) hold on p2 = plot(f2, 'b') hold off legend([p1; p2], 'Counts per Angle','Nearest', 'pchip')
For an alternative to 'cubicinterp' or 'pchipinterp', you can use other spline functions that allow greater control over what you can create. See About Splines in Curve Fitting Toolbox.