Main Content

prepareCurveData

Prepare data inputs for curve fitting

Description

example

[XOut,YOut] = prepareCurveData(XIn,YIn)transforms data, if necessary, for curve fitting with thefitfunction. TheprepareCurveDatafunction transforms data as follows:

  • Return data as columns regardless of the input shapes. Error if the number of elements do not match. Warn if the number of elements match, but the sizes differ.

  • Convert complex to real (remove imaginary parts) and warn of this conversion.

  • RemoveNaNorInffrom data and warn of this removal.

  • Convert nondouble to double and warn of this conversion.

SpecifyXInas empty if you want to fit curves toydata against the index. IfXInis empty, thenXOutis a vector of indices intoYOut. Thefitfunction can use the vectorXOutfor thexdata when there is onlyydata.

[XOut,YOut,WOut] = prepareCurveData(XIn,YIn,WIn)transforms data including weights (WIn) for curve fitting with thefitfunction.

When you generate code from the Curve Fitter app, the generated code includes a call toprepareCurveData(orprepareSurfaceDatafor surface fits). You can call the generated file from the command line with your original data or new data as input arguments, to recreate your fits and plots. If you call the generated file with new data, theprepareCurveDatafunction ensures you can use any data that you can fit in the Curve Fitter app, by reshaping if necessary to column doubles and removingNaNs,Infs, or the imaginary parts of complex numbers.

Examples

collapse all

The following commands load the exampletitaniumdata in whichxandyare row vectors. Attempting to use rows as inputs to thefitfunction produces an error. TheprepareCurveData功能重塑sxandyto columns for use with thefitfunction.

[x,y] = titanium(); [x,y] = prepareCurveData(x,y);

Create and plot a fit using the reshaped data.

f = fit(x,y,'smoothingspline'); plot(f,x,y)

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent data, fitted curve.

Input Arguments

collapse all

X data variable for curve fitting, specified as a scalar, a vector or a matrix.XIncan be empty. Specify empty ([ ]) when you want to fit curves toydata against index (x=1:length( y )). SeeYOut.

Data Types:double

Y data variable for curve fitting, specified as a scalar, a vector or a matrix.

Data Types:double

Weights variable for curve fitting specified, as a scalar, a vector or a matrix.

Data Types:double

Output Arguments

collapse all

X data column variable prepared for curve fitting, returned as a vector.

IfXInis empty, thenXOutis a vector of indices intoYOut. Thefitfunction can use the vectorXOutfor thexdata when there is onlyydata.

Data Types:double

Y data column variable prepared for curve fitting, returned as a vector.

Data Types:double

弗吉尼亚州权重列riable prepared for curve fitting, returned as a vector.

Data Types:double

Version History

Introduced in R2013a