| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Curve Fitting Toolbox |
| Contents | Index |
| Learn more about Curve Fitting Toolbox |
| On this page… |
|---|
Introducing the Surface Fitting Tool |
You can interactively fit surfaces to data and view plots with the flexible and intuitive Surface Fitting Tool graphical user interface. You can use Surface Fitting Tool to:
Create, plot, and compare multiple surface fits
Use linear or nonlinear regression, interpolation, local smoothing regression, or custom equations
View goodness-of-fit statistics, display confidence intervals and residuals, remove outliers and assess fits with validation data
Automatically generate M-code for fitting and plotting surfaces, or export fits to workspace for further analysis
The following image shows the Surface Fitting Tool displaying a session with multiple fits and plots.

The process of fitting a surface to data involves the following steps:
For instructions demonstrating how to load some example data and create a surface fit, see Interactive Surface Fitting Examples.
For next steps, see also Fitting Multiple Surfaces and Comparing Surface Fits
Open the Surface Fitting Tool using one of these methods:
Enter sftool at the MATLAB command line.
Select from the MATLAB Start menu:
Start > Toolboxes > Curve Fitting > Surface Fitting Tool (sftool)
Next, you are ready to select the data you want to fit to the surface.
To select data to fit, use the drop-down lists in the Surface Fitting Tool to select variables for X input, Y input and Z output.
Note To load example data to use in the Surface Fitting Tool, enter load franke at the command line. See Franke Data Interactive Surface Fitting Example for more instructions. |
You can use the Surface Fitting Tool drop-down lists to select any vector (of type double) in your MATLAB workspace.

Similarly you can select any vector (of type double) in your workspace to use as Weights.
When you select three variables, the Surface Fitting Tool immediately creates a fit with the default settings. You can turn off Auto fit to avoid time-consuming refitting for large data sets, by clearing the Auto fit check box.

Note The Surface Fitting Tool uses a snapshot of the data you select. Subsequent workspace changes to the data have no effect on your surface fits. If you want to update your fit data from the workspace, change the variable selection, and then reselect the variable with the drop-down controls. |
If there are problems with the data you select, you see messages in the Results pane. For example, the Surface Fitting Tool ignores Infs, NaNs, and imaginary components of complex numbers in the data, and you see messages in the Results pane in these cases.
If you see the following warning: Duplicate x-y data points detected: using average of the z values., this means that there are two or more data points where the input values (x, y) are the same or very close together. The default interpolant fit type needs to calculate a unique value at that point. You do not need do anything to fix the problem, this warning is just for your information. The Surface Fitting Tool automatically takes the average z value of any group of points with the same x-y values.
Other problems with your selected data can produce the following error: Error computing Delaunay triangulation. Please try again with different data. Some arrangements of data make it impossible for Surface Fitting Tool to compute a Delaunay triangulation. Three out of the four surface interpolation methods (linear, cubic, and nearest) require a Delaunay triangulation of the data. An example of data that can cause this error is a case where all the data lies on a straight line in x-y. In this case, Surface Fitting Tool cannot fit a surface to the data. You need to provide more data in order to fit a surface.
You can refine your fit, using any of the following optional steps:
Change fit type and settings. Select GUI settings to use the Surface Fitting Tool built-in fit types or create custom equations. Built-in fit types are Interpolant, Polynomial, and Lowess. See Selecting Fit Settings.
Exclude data by removing outliers in the Surface Fitting Tool. See Removing Outliers.
Select weights. See Selecting Data.
Select validation data. See Selecting Validation Data
Create multiple fits and you can compare different fit types and settings side by side in the Surface Fitting Tool. See Fitting Multiple Surfaces and Comparing Surface Fits.
To remove outliers, follow these steps:
Select Tools > Exclude Outliers.
When you move the mouse cursor to the plot, it changes to a cross-hair to show you are in outlier selection mode.
Click a point that you want to exclude in the surface plot or residuals plot. Alternatively, click and drag to define a rectangle and remove all enclosed points.
A removed plot point becomes a red star in the plots. If you have Auto-fit selected, the Surface Fitting Tool refits the surface without the point. Otherwise, you can click Fit to refit.
Repeat for all points you want to exclude.
When removing outliers, it can be helpful to display a 2-D residuals plot for examining and removing outliers. With your plot cursor in rotation mode (select Tools > Rotate 3D.) Next, right-click the plot to select X-Y, X-Z, or Y-Z view. The following image shows an X-Z plot with some outliers removed.

To replace excluded points in the fit, click them again in Exclude Outliers mode.
To specify validation data for the currently selected fit, follow these steps:
Select Fit > Specify Validation Data. The Specify Validation Data dialog box opens.
Select variables for X input, Y input, and Z output. You can use these drop-down lists to select any vector (of type double) in your MATLAB workspace.
When you select the three variables, the tool calculates validation statistics (SSE and RMSE) and displays them in the Results pane and the Table of Fits. For definitions of these statistics, see Using the Statistics in the Table of Fits. Your validation data points display on the surface plot and residual plot along with the original data.
Close the dialog box.
You can change mouse mode for manipulating plots, customize your view to show different plots of your fit, and control plot options with the Tools and View menus. This section describes the options available.
Use the Tools menu to toggle your mouse mode in your plots:
Rotate 3D selects click-and-drag rotation mode.
Data Cursor selects data cursor mode, where you can click points to display input and output values.
Exclude Outliers selects outlier mode, where you can click points to remove or include them in your fit. See Removing Outliers.
To customize your plot display, you can use the Tools menu or the View menu. See also Comparing Surface Fits.
Legend toggles display of the Legend on all plots in the currently selected fit tab.
Grid toggles display of the grid on all plots in the currently selected fit tab.
Surface Prediction Bounds allows you to choose which bounds to display: None, 90%, 95%, 99%, or Custom., The custom option opens a dialog box where you can enter the required confidence level.
Axes Limits opens a dialog box where you can specify upper and lower bounds for the X and Y axes of plots.
Default Axes Limits returns plots to the default axes limits.
Fit Settings toggles display of the fit controls pane in the currently selected fit tab (Fit name, inputs, fit type, and so on).
Fit Results toggles the display of the Results pane in the currently selected fit tab. When you display the Results pane, you can see model terms and coefficients, goodness-of-fit statistics, and information messages about the fit.
Surface Plot toggles display of the surface plot in the currently selected fit tab. This menu item is disabled if only the surface plot is displayed.
Residuals Plot toggles display of the residuals plot in the currently selected fit tab. This menu item is disabled if only the residuals plot is displayed.
Contour Plot toggles display of the contour plot in the currently selected fit tab. This menu item is disabled if only the contour plot is displayed.
![]() | Interactive Surface Fitting | Interactive Surface Fitting Examples | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |