| Contents | Index |
| On this page… |
|---|
You can fit curves and surfaces to data and view plots with the Curve Fitting Tool GUI. This tool lets you:
Create, plot, and compare multiple fits.
Use linear or nonlinear regression, interpolation, smoothing, and custom equations.
View goodness-of-fit statistics, display confidence intervals and residuals, remove outliers and assess fits with validation data.
Automatically generate code to fit and plot curves and surfaces, or export fits to the workspace for further analysis.
Load some example data at the MATLAB command line:
load census
Open the Curve Fitting Tool:
cftool
Select X data and Y data. For details, see Interactive Data Selection.

The Curve Fitting Tool creates a default polynomial fit to the data.
Try different fit options. For example, change the polynomial Degree to 3 to fit a cubic polynomial.

Select a different model type from the fit category list, e.g., Smoothing Spline. For information about models you can fit, see Model Types for Curves and Surfaces.

Select File > Generate Code.
The Curve Fitting Tool creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session.
Tip For a detailed workflow example, see Example: Interactive Curve Fitting. |
To create multiple fits and compare them, see Interactive Fit Comparison.
Load some example data at the MATLAB command line:
load franke
Open the Curve Fitting Tool:
cftool
Select X data, Y data and Z data. For more information, see Interactive Data Selection.

The Curve Fitting Tool creates a default interpolation fit to the data.
Select a different model type from the fit category list, e.g., Polynomial.
For information about models you can fit, see Model Types for Curves and Surfaces.

Try different fit options for your chosen model type.
Select File > Generate Code.
The Curve Fitting Tool creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session.
Tip For a detailed example, see Example: Interactive Surface Fitting. |
To create multiple fits and compare them, see Interactive Fit Comparison.
Based on your selected data, the fit category list shows either curve or surface fit categories. The following table describes the options for curves and surfaces.
| Fit Category | Curves | Surfaces |
|---|---|---|
| Regression Models | ||
| Polynomial | Yes (up to degree 9) | Yes (up to degree 5) |
| Exponential | Yes | |
| Fourier | Yes | |
| Gaussian | Yes | |
| Power | Yes | |
| Rational | Yes | |
| Sum of Sine | Yes | |
| Weibull | Yes | |
| Interpolation | ||
| Interpolant | Yes Methods: Nearest neighbor Linear Cubic Shape-preserving (PCHIP) | Yes Methods: Nearest neighbor Linear Cubic Biharmonic (v4) |
| Smoothing | ||
| Smoothing Spline | Yes | |
| Lowess | Yes | |
| Custom | ||
| Custom Equation | Yes | Yes |
For information about these fit types, see:
![]() | Interactive Fitting | Interactive Data Selection | ![]() |
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |