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

    %% Histogram of Linear Model Residuals
% Plot a histogram of the residuals of a fitted linear model.   

%% 
% Load the |carsmall| data and fit a linear model of the mileage as a function
% of model year, weight, and weight squared. 
load carsmall
tbl = table(MPG,Weight);
tbl.Year = ordinal(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');  

%% 
% Plot the raw residuals. 
plotResiduals(mdl)