## 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 . 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 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:

`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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7450964,"math_prob":0.8711615,"size":1404,"snap":"2023-14-2023-23","text_gpt3_token_len":323,"char_repetition_ratio":0.17357142,"word_repetition_ratio":0.08583691,"special_character_ratio":0.20512821,"punctuation_ratio":0.11313868,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95267344,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-31T11:15:03Z\",\"WARC-Record-ID\":\"<urn:uuid:2043108b-7160-4de8-b032-5847bb979b7f>\",\"Content-Length\":\"75757\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:363acf70-4452-4d01-b92a-64888c73128e>\",\"WARC-Concurrent-To\":\"<urn:uuid:df251fa6-e987-4d5e-8523-9d9a7c1057aa>\",\"WARC-IP-Address\":\"104.96.217.125\",\"WARC-Target-URI\":\"https://ch.mathworks.com/help/curvefit/curve-fitting.html\",\"WARC-Payload-Digest\":\"sha1:YM2Y2LIT2T6Z5OWHS7A7LUSOSOGCXIQ5\",\"WARC-Block-Digest\":\"sha1:WM5EFRC26F6OEOM2HI2SKI5T7YYHFV2O\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224646457.49_warc_CC-MAIN-20230531090221-20230531120221-00338.warc.gz\"}"}