Main Content

Selecting an Interpolant Fit

Select Interpolant Fit Interactively

Open the Curve Fitter app by enteringcurveFitterat the MATLAB®command line. Alternatively, on theAppstab, in theMath, Statistics and Optimizationgroup, clickCurve Fitter.

On theCurve Fittertab, in theFit Typesection, select anInterpolantfit. When you select anInterpolantfit, the app fits an interpolating curve or surface that passes through every data point.

In theFit Optionspane, you can specify theMethodvalue.

Fit Options pane for interpolant fit

For curve data, you can setMethodtoLinear,Nearest neighbor,Cubic Spline, orShape-preserving (PCHIP). For surface data, you can setMethodtoNearest neighbor,Linear,Cubic Spline,Biharmonic (v4), orThin-plate spline.

For surfaces, theInterpolantfit uses thescatteredInterpolantfunction for theLinearandNearest neighbormethods, thegriddatafunction for theCubic SplineandBiharmonic (v4)methods, and thetpapsfunction for theThin-plate splinemethod. Try theThin-plate splinemethod when you require both smooth surface interpolation and good extrapolation properties. For more details, seeAbout Interpolation Methods.

Tip

If your data variables have very different scales, select and clear theCenter and scalecheck box to see the difference in the fit. Normalizing the inputs can strongly influence the results of the triangle-based (that is, piecewiseLinearandCubic Splineinterpolation) andNearest neighborsurface interpolation methods.

Fit Linear Interpolant Models Using thefitFunction

This example shows how to use thefitfunction to fit linear interpolant models to data.

Interpolant Fitting Methods

Specify the interpolant model method when calling thefitfunction using one of the options outlined inInterpolant Model Names. None of the interpolant methods has any additional fit option parameters.

Fit a Linear Interpolant Model

Load data and fit a linear interpolant model using the'linearinterp'option.

loadcensusf = fit(cdate,pop,'linearinterp'); plot(f,cdate,pop);

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent data, fitted curve.

Compare Linear Interpolant Models

Load data and create both nearest neighbor and pchip interpolant fits using the'nearestinterp'and“pchip”options.

loadcarbon12alphaf1 = fit(angle,counts,'nearestinterp'); f2 = fit(angle,counts,“pchip”);

Compare the fitted curvesf1andf2on a plot.

p1 = plot(f1,angle,counts); xlim([min(angle),max(angle)]) holdonp2 = plot(f2,'b'); holdofflegend([p1;p2],'Counts per Angle','Nearest Neighbor',“pchip”,...'Location','northwest')

Figure contains an axes object. The axes object contains 3 objects of type line. These objects represent Counts per Angle, Nearest Neighbor, pchip.

为另一个“cubicinterp”或“pchipinterp', you can use other spline functions that give you greater control over what you create. SeeIntroducing Spline Fitting.

See Also

Apps

Functions

Related Topics