Main Content

Introducing Spline Fitting

Spline Overview

The Curve Fitting Toolbox™ spline functions are a collection of tools for creating, viewing, and analyzing spline approximations of data. Splines are smooth piecewise polynomials that you can use to represent functions over large intervals, where it would be impractical to use a single approximating polynomial.

The spline functionality includes a tool that provides easy access to functions for creating, visualizing, and manipulating splines. The toolbox also contains functions that enable you to evaluate, plot, combine, differentiate, and integrate splines. Because all toolbox functions are implemented in the open MATLAB® language, you can inspect the algorithms, modify the source code, and create your own custom functions.

Key spline features:

  • Tools that let you create, view, and manipulate splines and manage and compare spline approximations

  • Functions for advanced spline operations, including differentiation, integration, break/knot manipulation, and optimal knot placement

  • Support for piecewise polynomial form (ppform) and basis form (B-form) splines

  • Support for tensor-product splines and rational splines (including NURBS)

In Curve Fitting Toolbox you can fit splines interactively or programmatically.

Interactive Spline Fitting

Use the Curve Fitter app or the Spline Tool to interactively create spline fits.

Open the Curve Fitter app by entering curveFitter at the MATLAB command line. Alternatively, on the Apps tab, in the Math, Statistics and Optimization group, click Curve Fitter. The Curve Fitter app supports the same spline fitting options as the fit function.

Open the Spline Tool by entering splinetool at the command line. The Spline Tool supports all spline functions. Use the tool to do the following:

  • Vary spline parameters and tolerances.

  • View and modify data, breaks, knots, and weights.

  • View the error of the spline, or the spline's first or second derivative.

  • Observe the toolbox commands that generated your spline.

  • Create and import data, including built-in instructive data sets, and save splines to the workspace.

For more information, see splinetool.

Programmatic Spline Fitting

Use the fit function to do the following:

  • Fit cubic spline interpolants to curves or surfaces.

  • Fit smoothing splines and shape-preserving cubic spline interpolants only to curves.

  • Fit thin-plate splines only to surfaces.

Curve Fitting Toolbox also provides specific splines functions that allow more control and flexibility when you fit splines. For example, use the csapi function, instead of fit with fitType set to "cubicinterp", if you want to do one of the following:

  • Combine the results with other splines, for example, by addition.

  • Create vector-valued splines. You can use csapi with scalars, vectors, matrices, and ND-arrays. The fit function supports only scalar-valued splines.

  • Create other types of splines such as ppform, B-form, tensor-product, rational, and stform thin-plate splines.

  • Create splines without data.

  • Specify breaks, optimize knot placement, and use specialized functions for spline manipulation such as differentiation and integration.

For more information on how to create splines including B-form, tensor-product, NURBs, and other rational splines, see Spline Construction.

See Also