Selecting an Interpolant Fit
Select Interpolant Fit Interactively
Open the Curve Fitter app by enteringcurveFitter
at 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.
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 thescatteredInterpolant
function for theLinear
andNearest neighbor
methods, thegriddata
function for theCubic Spline
andBiharmonic (v4)
methods, and thetpaps
function for theThin-plate spline
method. Try theThin-plate spline
method 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, piecewiseLinear
andCubic Spline
interpolation) andNearest neighbor
surface interpolation methods.
Fit Linear Interpolant Models Using thefit
Function
This example shows how to use thefit
function 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);
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 curvesf1
andf2
on 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')
为另一个“cubicinterp”或“pchipinterp', you can use other spline functions that give you greater control over what you create. SeeIntroducing Spline Fitting.