interactive curve and surface fitting -凯发k8网页登录

main content

interactive curve and surface fitting

introducing curve fitter app

you can fit curves and surfaces to data and view plots with the curve fitter app.

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

fit curve

  1. load some example data at the matlab® command line.

    load census
  2. open the curve fitter app.

    curvefitter
    alternatively, on the apps tab, in the math, statistics and optimization group, click curve fitter.
  3. on the curve fitter tab, in the data section, click select data. in the select fitting data dialog box, select cdate as the x data value and pop as the y data value. for details, see selecting data to fit in curve fitter app.

    select fitting data dialog box, populated by the census data

    the curve fitter app creates a default polynomial fit to the data.

  4. try different fit options. for example, in the fit options pane, change the polynomial degree value to 3 to fit a cubic polynomial.

    fit options pane for a polynomial fit

  5. select a different model type from the fit gallery in the fit type section on the curve fitter tab. for example, click the arrow to open the gallery, and click smoothing spline in the smoothing group. for information about models you can fit, see model types for curves and surfaces.

    fit type gallery, listing available two-dimensional model types

  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.

tip

for a detailed workflow example, see compare fits in curve fitter app.

to create multiple fits and compare them, see .

fit surface

  1. load some example data at the matlab command line.

    load franke
  2. open the curve fitter app.

    curvefitter
  3. on the curve fitter tab, in the data section, click select data. in the select fitting data dialog box, select x as the x data value, y as the y data value, and z as the z data value. for more information, see selecting data to fit in curve fitter app.

    select fitting data dialog box, populated by the franke data

    the curve fitter app creates a default interpolation fit to the data.

  4. select a different model type from the fit gallery in the fit type section on the curve fitter tab. for example, click the arrow to open the gallery, and click polynomial in the regression models group.

    for information about models you can fit, see model types for curves and surfaces.

    fit type gallery, listing available three-dimensional model types

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

tip

for a detailed example, see .

to create multiple fits and compare them, see .

model types for curves and surfaces

based on your selected data, the fit gallery shows either curve or surface fit groups. the following table describes the options for curves and surfaces.

fit groupfit typecurvessurfaces
regression modelsyes (up to degree 9)yes (up to degree 5)
exponentialyesno
yesno
yesno
yesno
yesno
yesno
yesno
interpolationinterpolant

yes, with methods:

  • nearest neighbor

  • linear

  • cubic

  • shape-preserving (pchip)

yes, with methods:

  • nearest neighbor

  • linear

  • cubic

  • biharmonic (v4)

  • thin-plate spline

smoothingyesno
noyes
customyesyes
linear fittingyesno

for information about these fit types, see:

selecting data to fit in curve fitter app

to select data to fit in the curve fitter app, click select data in the data section on the curve fitter tab. you can select variables in your matlab workspace.

  • to fit curves:

    • in the select fitting data dialog box, select x data and y data.

    • select only y data to plot y against the index x = 1:length(y).

  • to fit surfaces, select x data, y data, and z data in the select fitting data dialog box.

in the select fitting data dialog box, you can use the drop-down lists to select any numeric variable in your matlab workspace that has more than one element. you can also select a numeric variable that is a column in a table variable. first select the table name, and then select the column name.

similarly, you can select any numeric variable in your workspace to use as weights, including a numeric table column.

select fitting data dialog box with table variable selections

for curves, the x and y variables must have the same number of elements. if you specify weights, the weights variable must have the same number of elements as the other data variables.

for surfaces, the x, y, and z variables must be either arrays with the same number of elements, or two vectors (x and y) representing the row and column headers of a matrix z. if you specify weights, the weights variable must have the same number of elements as the z variable.

for more information, see .

when you select variables, the curve fitter app immediately creates a curve or surface fit with the default settings. if you want to avoid time-consuming refitting for large data sets, you can turn off the automatic behavior. on the curve fitter tab, in the fit section, select manual.

note

the curve fitter app uses a snapshot of the data you select. subsequent workspace changes to the data have no effect on your fits. to update your fit data from the workspace, first change the variable selection, and then reselect the variable with the drop-down controls.

if there are problems with the data you select, you can see messages in the results pane. for example, the curve fitter app ignores infs, nans, and imaginary components of complex numbers in the data, and displays messages in the results pane in these cases.

if you see warnings about reshaping your data or incompatible sizes, read and for more information.

save and reopen sessions

you can save and reopen sessions for easy access to multiple fits. the session file contains all the fits and variables in your session and remembers your layout.

to save your session, first click the save button in the file section on the curve fitter tab to open your file browser. next, select a name and location for your session file (with the file extension .sfit).

after you save your session once, you can click save and select save session to overwrite that session with subsequent saves.

to save the current session under a different name, click save and select save session as.

to reopen a session, click open in the file section on the curve fitter tab to open a file browser where you can select a saved curve fitting session file to load.

related topics

网站地图