Skip to Main Content Skip to Search
Product Documentation

Curve Fitting

Interactive Curve Fitting

To interactively fit a curve, follow the steps in this simple example:

  1. Load some data at the MATLAB command line.

    load hahn1
  2. Open Curve Fitting Tool. Enter:

    cftool
  3. In Curve Fitting Tool, select X Data and Y Data.

    Curve Fitting Tool creates a default interpolation fit to the data.

  4. Choose a different model type using the fit category drop-down list, e.g., select Polynomial.

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

  6. Select File > Generate Code.

    Curve Fitting Tool creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session.

See Interactive Fitting for information on the following topics:

  1. Fitting a curve

  2. Selecting fit settings

  3. Creating multiple fits

  4. Comparing fits

  5. Generating code files and exporting fits to the workspace

For details and examples of specific model types and fit analysis, see the following sections:

  1. Linear and Nonlinear Regression

  2. Interpolation and Smoothing

  3. Fit Postprocessing

Programmatic Curve Fitting

To programmatically fit a curve, follow the steps in this simple example:

  1. 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 )

See these sections:

  1. Command-Line Curve and Surface Fitting

  2. Curve and Surface Fitting Objects and Methods

For details and examples of specific model types and fit analysis, see the following sections:

  1. Linear and Nonlinear Regression

  2. Interpolation and Smoothing

  3. Fit Postprocessing

  


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