prepareSurfaceData

Prepare data inputs for surface fitting

Syntax

[XOut, YOut, ZOut] = prepareSurfaceData(XIn, YIn, ZIn)
[XOut, YOut, ZOut, WOut] = prepareSurfaceData(XIn, YIn, ZIn, WIn)

Description

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

  • For grid vectors, transform row (YIn) and column (XIn) headers into arrays YOut and XOut that are the same size as ZIn. Warn if XIn and YIn are 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.

  • Remove NaN or Inf from 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 the fit function.

Use prepareSurfaceData if your data is not in column vector form. For example, you have 3 matrices. You can also use prepareSurfaceData if you have grid vectors, where length(XIn) = n, length(YIn) = m and size(ZIn) = [m,n]. You must process grid vector data for use with the fit function by using prepareSurfaceData. If you use Curve Fitting 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 use prepareSurfaceData. You can specify variables in a MATLAB table as inputs to the fit function using the form tablename.varname.

When you generate code from Curve Fitting app, the generated code includes a call to prepareSurfaceData (or prepareCurveData for 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, the prepareCurveData function ensures you can use any data that you can fit in Curve Fitting app, by reshaping if necessary and removing NaNs, Infs, or the imaginary parts of complex numbers.

Examples

Prepare surface data for the fit function

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

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

Use the prepareSurfaceData to convert rows to columns, nondoubles to doubles, and remove Nan and Inf.

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

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

Use whos to check that the prepareSurfaceData converted the variables to column vectors that are doubles.

whos xo yo zo 

Introduced in R2010b