Curve Fitting Toolbox | ![]() ![]() |
Syntax
ftype = fittype('ltype
') ftype = fittype('expr') ftype = fittype('expr','PropertyName
',PropertyValue,...)
Arguments
Description
ftype = fittype('
creates the fit type object ltype
')
ftype
from the library model, spline, or interpolant specified by ltype
. You can display the library fit type names with the cflibhelp
function.
ftype = fittype('expr')
creates the fit type object from the expression specified by expr
. The expression expr
represents the custom model you will use to fit your data. To create a general (nonlinear) custom model, specify the entire equation as one expression. To create a linear custom model, pass in a cell array of expressions to expr
but do not include the coefficients. Each element of the cell array corresponds to one term of the model. If there is a constant term, use "1" as the corresponding element in the cell array.
By default, the independent variable is assumed to be x
, the dependent variable is assumed to be y
, there are no problem-dependent variables, and all other variables are assumed to be coefficients of the model. All coefficients must be scalars.
ftype = fittype('expr','
creates a fit type object using the specified property name/property value pairs. The supported property names are given below.PropertyName
',PropertyValue,...)
Example
Create a fit type object for a custom general equation and define the problem-dependent name to be n
.
Define the independent variable to be chan
.
ftype = fittype('a*chan+b*exp(n*chan)','ind','chan','prob','n') ftype = General model: ftype(a,b,n,chan) = a*chan+b*exp(n*chan)
Create a fit type object for a custom linear equation and specify names for the coefficients.
ftype = fittype({'cos(x)','1'},'coeff',{'a1','a2'}) ftype = Linear model: ftype(a1,a2,x) = a1*cos(x) + a2
Create a fit type object for the rat33
library model. Note that the display includes the full equation.
ftype = fittype('rat33') ftype = General model Rat33: ftype(p1,p2,p3,p4,q1,q2,q3,x) = (p1*x^3 + p2*x^2 + p3*x + p4)/ (x^3 + q1*x^2 + q2*x + q3)
Create a fit type object and include the existing fit options object opts
, and fit to the census data.
load census opts = fitoptions('Method','Nonlinear','Normalize','On'); ftype = fittype('a*exp(b*x)+c','options',opts); f1 = fit(cdate,pop,ftype);
![]() | fitoptions | get | ![]() |