Extend linear regression line to an offset

17 ビュー (過去 30 日間)
caroline Øhrstrøm
caroline Øhrstrøm 2020 年 3 月 27 日
回答済み: Star Strider 2020 年 3 月 27 日
Hello
I am working an a calibration and I would like my graph to go to the offset, meaning it has to continue from their it though 0.0, but do not know how to set the range, my code is as following.
X = [0.6,1.6,2.6,3.6,4.6,5.6,];
Y = [23500, 87780, 153651, 220054, 283688,344890];
myFit = LinearModel.fit(X,Y);
plot(myFit)
Hope someone can help:)

回答 (1 件)

Star Strider
Star Strider 2020 年 3 月 27 日
I am not certain what you are asking.
Two possibilities:
X = [0.6,1.6,2.6,3.6,4.6,5.6,];
Y = [23500, 87780, 153651, 220054, 283688,344890];
B0 = X(:) \ Y(:); % Force Zero Intercept
B0Fit = [0 max(X)] * B0;
Bnz = [X(:) ones(size(X(:)))] \ Y(:); % Non-Zero Intercept
BnzFit = [0 1; max(X) 1] * Bnz;
figure
plot(X,Y,'p')
hold on
plot([0 max(X)], B0Fit,'-r')
plot([0 max(X)], BnzFit,'-g')
hold off
grid
legend('Data', 'Force Zero Intercept', 'Extend To Zero', 'Location','E')
This extends both regressions through ‘X=0’. One forces a (0,0) intercept (returning only the slope), the other does not (returning both the slope and the non-zero intercept).

カテゴリ

Help Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by