Main Content

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 the Curve Fitter app.

    curveFitter

  3. In the Curve Fitter app, on the Curve Fitter tab, in the Data section, click Select Data. In the Select Fitting Data dialog box, select temp as the X Data value and thermex as the Y Data value.

    The Curve Fitter app creates a default polynomial fit to the data.

  4. Choose a different model type from the fit gallery in the Fit Type section of the Curve Fitter tab.

  5. In the Fit Options pane, try different fit options for your chosen model type.

  6. In the Export section, click Export and select Generate Code.

    The Curve Fitter app creates a file in the Editor containing MATLAB code to recreate the currently selected fit and its opened plots in your interactive session.

For more information about fitting curves in the Curve Fitter app, see Interactive Curve and Surface Fitting.

Programmatic Curve Fitting

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

  1. Load some data.

    load hahn1

  2. 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")

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

See Also

|

Related Topics