To interactively fit a curve, follow the steps in this simple example:
Load some data at the MATLAB® command line.
load hahn1
Open the Curve Fitting app. Enter:
cftool
In the Curve Fitting app, select X Data and Y Data.
Curve Fitting app creates a default interpolation fit to the data.
Choose a different model type using the fit category drop-down list, e.g., select Polynomial.
Try different fit options for your chosen model type.
Select File > Generate Code.
Curve Fitting app creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session.
For more information about fitting curves in the Curve Fitting app, see Interactive Curve and Surface Fitting.
For details and examples of specific model types and fit analysis, see the following sections:
To programmatically fit a curve, follow the steps in this simple example:
Load some data.
load hahn1
Create a fit using the fit
function,
specifying the variables and a model type (in this case rat23
is
the model type).
f = fit( temp, thermex, 'rat23' )
Plot your fit and the data.
plot( f, temp, thermex ) f( 600 )
To learn what functions you can use to create and work with fits, see: Curve and Surface Fitting.
For details and examples of specific model types and fit analysis, see the following sections: