Products & Services Solutions Academia Support User Community Company

Learn more about Curve Fitting Toolbox   

Fitting a Surface

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:

The following image shows the Surface Fitting Tool displaying a session with multiple fits and plots.

How to Fit a Surface

The process of fitting a surface to data involves the following steps:

  1. Opening the Surface Fitting Tool

  2. Selecting Data

  3. Refining Your Fit

  4. Removing Outliers

  5. Selecting Validation Data

  6. Exploring and Customizing Plots

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

Opening the Surface Fitting Tool

Open the Surface Fitting Tool using one of these methods:

Next, you are ready to select the data you want to fit to the surface.

Selecting Data

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.

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.

Troubleshooting Data Problems

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.

Refining Your Fit

You can refine your fit, using any of the following optional steps:

Removing Outliers

To remove outliers, follow these steps:

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

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

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

Selecting Validation Data

To specify validation data for the currently selected fit, follow these steps:

  1. Select Fit > Specify Validation Data. The Specify Validation Data dialog box opens.

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

  3. Close the dialog box.

Exploring and Customizing Plots

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.

Using Rotation, Data Cursor, and Outlier Exclusion

Use the Tools menu to toggle your mouse mode in your plots:

Customizing the Fit Display

To customize your plot display, you can use the Tools menu or the View menu. See also Comparing Surface Fits.

Tools Menu.  

View Menu.  

  


Recommended Products

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