【发布时间】:2018-04-10 12:53:51
【问题描述】:
我正在使用 MATLB 的 fitlm 函数对我的数据进行线性回归。这很容易完成。我还不确定如何绘制我的数据。例如,从回归表中,如果您运行下面的代码,我认为回归线的截距 = 0.023851 和斜率 = 0.56421。但是,当我按照 MATLAB 的说明确定截距和斜率时(参见下面的代码),我得到了其他值。哪些是正确的,为什么是这样?
x = [0.0001;0.066578214;0.09611659;0.075839223;0.125;0.037889785;0.070220426;0.070648;0.082886425;0.095050538;0.058966667;0.0456;0.070994624;0.048540228;0.06561828;0.053916667;0.035954301;0.037634409;0.044335551;0.061270917;0.163333333;0.079986559;0.070616667]
y = [0.082;0.0452;0.072340;0.0543;0.0932;0.0321;0.078;0.06021;0.0734;0.103;0.0436;0.0482;0.08732;0.05421;0.0589;0.04321;0.043215;0.054321;0.05467;0.0432;0.109;0.0723;0.09821]
mdl = fitlm(x,y,'linear','RobustOpts','on')
%% plot raw data
hold on
plot(x,y,'*') % plot datapoints
%% as suggested by matlab on https://ch.mathworks.com/help/matlab/data_analysis/linear-regression.html
X = [ones(length(x),1) x];
b = X\y % this is however another intercept as seen in the table!
yCalc2 = X*b;
plot(x,yCalc2,'-')
legend('Data','Slope','Slope & Intercept','Location','best');
【问题讨论】:
标签: matlab plot regression