ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn)
Predictor components. Xnewi can be one of:
Each nonscalar component must have the same size (number of elements in each dimension).
If you pass just one Xnew array, Xnew can be a table, dataset array, or an array of doubles, where each column of the array represents one predictor.
Predicted mean values at Xnew. ypred is the same size as each component of Xnew.
For models with an offset, feval uses 0 as the offset value.
Fit a mileage model to the smallcar data, including the Year categorical predictor. Superimpose fitted curves on a scatter plot of the data.
Load the data and fit a model.
load carsmall tbl = table(MPG,Weight); tbl.Year = ordinal(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight^2');
Create a scatter plot of the mileage versus weight.
Use feval to plot curves of the model predictions for the various years and weights.
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')
predict gives the same predictions, but uses a single input array with one observation in each row, rather than one component in each input argument. predict also gives confidence intervals on its predictions.
random predicts with added noise.