www.gusucode.com > stats 源码程序 matlab案例代码 > stats/AddaTermtoaModelExample.m
%% Add Terms to Linear Regression Model % Create a model of the |carsmall| data without any interactions, then add % an interaction term. %% % Load the |carsmall| data and make a model of the MPG as a function of % weight and model year. load carsmall tbl = table(MPG,Weight); tbl.Year = categorical(Model_Year); mdl = fitlm(tbl,'MPG ~ Year + Weight^2'); %% % Add an interaction term to |mdl|. terms = 'Year*Weight'; mdl1 = addTerms(mdl,terms)