Main Content

feval

Evaluate cfit, sfit, or fittype object

Description

Note

You can use feval to evaluate fits, but you can treat fit objects as functions and call feval indirectly using this syntax instead:

y = cfun(x)        % cfit objects;
z = sfun(x,y)      % sfit objects 
z = sfun([x, y])   % sfit objects 
y = ffun(coef1,coef2,...,x)   % curve fittype objects;
z = ffun(coef1,coef2,...,x,y) % surface fittype objects;

Alternatively, you can use the feval method to evaluate the estimated function, either at your original data points, or at new locations. The latter is referred to as interpolation or prediction, depending on the type of model. You can also use feval to extrapolate the estimated function's value at new locations that are not within the range of the original data.

y = feval(cfun,x) evaluates the cfit object cfun at the predictor values in the column vector x and returns the response values in the column vector y.

example

z = feval(sfun,[x,y]) evaluates the sfit object sfun at the predictor values in the two column matrix [x,y] and returns the response values in the column vector z.

z = feval(sfun,x,y) evaluates the sfit object sfun at the predictor values in the matrices x and y that must be the same size. It returns the response values in the matrix z that will be the same size as x and y.

y = feval(ffun,coeff1,coeff2,...,x) assigns the coefficients coeff1, coeff2, etc. to the fittype object ffun, evaluates it at the predictor values in the column vector x, and returns the response values in the column vector y. ffun cannot be a cfit object in this syntax. To evaluate cfit objects, use the first syntax.

z = feval(ffun,coeff1,coeff2,...,x,y) achieves a similar result for a fittype object for a surface.

Examples

collapse all

Create the fittype and cfit objects, and a random matrix of predictor values.

f = fittype('a*x^2+b*exp(n*x)');
c = cfit(f,1,10.3,-1e2);
X = rand(2)
X =
    0.0579    0.8132
    0.3529    0.0099

To evaluate the fittype object, f, call the feval function.

y1 = feval(f,1,10.3,-1e2,X)
y1 =
    0.0349    0.6612
    0.1245    3.8422

Alternatively, you can treat fit objects as functions and call feval indirectly using this syntax.

y1 = f(1,10.3,-1e2,X)
y1 =
    0.0349    0.6612
    0.1245    3.8422

Now evaluate the cfit object, c.

y2 = feval(c,X)
y2 =
    0.0349
    0.1245
    0.6612
    3.8422

Alternatively, call feval indirectly.

y2 = c(X)
y2 =
    0.0349
    0.1245
    0.6612
    3.8422

Input Arguments

collapse all

Function to evaluate, specified as a cfit object.

Function to evaluate, specified as an sfit object.

Function to evaluate, specified as a fittype object.

Points at which to evaluate the function, specified as a vector or matrix.

Points at which to evaluate the function, specified as a vector or matrix.

One or more coefficients assigned to the fittype object ffun, specified as scalars.

Output Arguments

collapse all

Response values of the function evaluated at the predictors values in the column vector x, returned as a column vector.

Response values of the function evaluated at the predictors values in the two column matrix [x,y], returned as a matrix.

Version History

Introduced before R2006a