Main Content

prepareSurfaceData

Prepare data inputs for surface fitting

Description

example

[XOut,YOut,ZOut] = prepareSurfaceData(XIn,YIn,ZIn)transforms data, if necessary, for surface fitting with thefitfunction. The function transforms data as follows:

  • For grid vectors, transform row (YIn) and column (XIn) headers into arraysYOutandXOutthat are the same size asZIn. Warn ifXInandYInare reversed.

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

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

[XOut,YOut,ZOut,WOut] = prepareSurfaceData(XIn,YIn,ZIn,WIn)transforms data including weights (WIn) for surface fitting with thefitfunction.

UseprepareSurfaceDataif your data is not in column vector form. For example, you have 3 matrices. You can also useprepareSurfaceDataif you have grid vectors, wherelength(XIn) = n, length(YIn) = mandsize(ZIn) = [m,n]. You must process grid vector data for use with thefitfunction by usingprepareSurfaceData. If you use the Curve Fitter app, you can select grid vector data and it automatically converts the data for you.

If your data is in a MATLAB®table, you do not need to useprepareSurfaceData. You can specify variables in a MATLAB table as inputs to thefitfunction using the formtablename.varname.

When you generate code from the Curve Fitter app, the generated code includes a call toprepareSurfaceData(orprepareCurveDatafor curve 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 and removingNaNs,Infs, or the imaginary parts of complex numbers.

Examples

collapse all

Create some data that is unsuitable for the fit function without preprocessing, because it is nondouble, noncolumn, and contains someNanandInfvalues.

x = int32(1:4); y = int32(1:5); z = rand(5,4); z(13) = Inf; z(3) = NaN;

Use theprepareSurfaceDatato convert rows to columns, nondoubles to doubles, and removeNanandInf.

[xo,yo,zo] = prepareSurfaceData(x,y,z);

The function displays the same warnings that you see if you select this data in the Curve Fitter app. The warnings tell you how your data is processed to be suitable for thefitfunction.

Usewhosto check that theprepareSurfaceDataconverted the variables to column vectors that are doubles.

whosxoyozo

Input Arguments

collapse all

X数据变量准备表面拟合,specified as a scalar, a vector or a matrix.

Data Types:double

Y data variable to prepare for surface fitting, specified as a scalar, a vector or a matrix.

Data Types:double

Z data variable to prepare for surface fitting, specified as a scalar, a vector or a matrix.

Data Types:double

Weights variable to prepare for surface fitting, specified as a scalar, a vector or a matrix.

Data Types:double

Output Arguments

collapse all

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

Data Types:double

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

Data Types:double

Z data column variable prepared for surface fitting, returned as a vector.

Data Types:double

Weights column variable prepared for surface fitting, returned as a vector.

Data Types:double

Version History

Introduced in R2010b