Extend linear regression line to an offset
21 views (last 30 days)
Show older comments
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:)
0 Comments
Answers (1)
Star Strider
on 27 Mar 2020
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).
0 Comments
See Also
Categories
Find more on Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!