Skip to Main Content Skip to Search
Product Documentation

Interactive Curve and Surface Fitting

Introducing the Curve Fitting Tool

You can fit curves and surfaces to data and view plots with the Curve Fitting Tool GUI. This tool lets you:

Fitting a Curve

  1. Load some example data at the MATLAB command line:

    load census
  2. Open the Curve Fitting Tool:

    cftool
  3. Select X data and Y data. For details, see Interactive Data Selection.

    The Curve Fitting Tool creates a default polynomial fit to the data.

  4. Try different fit options. For example, change the polynomial Degree to 3 to fit a cubic polynomial.

  5. 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.

  6. 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.

To create multiple fits and compare them, see Interactive Fit Comparison.

Fitting a Surface

  1. Load some example data at the MATLAB command line:

    load franke
  2. Open the Curve Fitting Tool:

    cftool
  3. 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.

  4. 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.

  5. Try different fit options for your chosen model type.

  6. 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.

To create multiple fits and compare them, see Interactive Fit Comparison.

Model Types for Curves and Surfaces

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 CategoryCurvesSurfaces
Regression Models
PolynomialYes (up to degree 9)Yes (up to degree 5)
ExponentialYes 
FourierYes 
GaussianYes 
PowerYes 
RationalYes 
Sum of SineYes 
WeibullYes 
Interpolation
InterpolantYes
Methods:
Nearest neighbor
Linear
Cubic
Shape-preserving (PCHIP)
Yes
Methods:
Nearest neighbor
Linear
Cubic
Biharmonic (v4)
Smoothing
Smoothing SplineYes 
Lowess Yes
Custom
Custom EquationYesYes

For information about these fit types, see:

  


 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS