feval

Evaluate cfit, sfit, or fittype object

Syntax

y = feval(cfun,x)
z = feval(sfun,[x,y])
z = feval(sfun,x,y)
y = feval(ffun,coeff1,coeff2,...,x)
z = feval(ffun,coeff1,coeff2,...,x,y)

Description

You can use feval to evaluate fits, but the following simpler syntax is recommended to evaluate these objects, instead of calling feval directly. You can treat fit objects as functions and call feval indirectly using the following syntax:

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

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

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

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

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

See Also

| |

Introduced before R2006a