feval

ypred = feval( mdl , Xnew1,Xnew2. Xnewn ) returns the predicted response of mdl to the new input predictors Xnew1,Xnew2. Xnewn .

Examples

Plot Different Categorical Levels

Fit a mileage model to the carsmall data set, including the Year categorical predictor. Superimpose fitted curves on a scatter plot of the data.

Load the data set and fit the model.

load carsmall tbl = table(MPG,Weight); tbl.Year = categorical(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight^2');

Create a scatter plot of MPG versus Weight , grouped by Year .

gscatter(tbl.Weight,tbl.MPG,tbl.Year,'rgb');

Plot curves of the model predictions for the various years and weights by using feval .

w = linspace(min(tbl.Weight),max(tbl.Weight))'; line(w,feval(mdl,w,'70'),'Color','r') line(w,feval(mdl,w,'76'),'Color','g') line(w,feval(mdl,w,'82'),'Color','b')

Input Arguments

mdl — Linear regression model object
LinearModel object | CompactLinearModel object

Linear regression model object, specified as a LinearModel object created by using fitlm or stepwiselm , or a CompactLinearModel object created by using compact .

Xnew1,Xnew2. Xnewn — New predictor input values
vector | matrix | table | dataset array

New predictor values, specified as a vector, matrix, table, or dataset array.

Data Types: single | double | table

Output Arguments

ypred — Predicted response values
numeric vector

Predicted response values at Xnew1,Xnew2. Xnewn , returned as a numeric vector.

Tips

Alternative Functionality

Extended Capabilities

GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox) .

Version History

Introduced in R2012a