www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ModifyaLinearModelExample.m

    %% Modify a Linear Regression Model Using |step|
% Fit a linear model to car data. Use |step| to evaluate whether a
% quadratic model improves the fit quality. 

%% 
% Load |carsmall| data, and create a table using weight and model year predictors
% with MPG response.
load carsmall
tbl = table(MPG,Weight);
tbl.Year = categorical(Model_Year);  

%% 
% Make a linear model of |MPG| as a function of |Year| and |Weight|. 
mdl = fitlm(tbl,'MPG ~ Year + Weight')  

%% 
% Use |step| to adjust the model to potentially include full quadratic terms. 
mdl1 = step(mdl,'upper','quadratic')