Extend linear regression line to an offset
이전 댓글 표시
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
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).
카테고리
도움말 센터 및 File Exchange에서 Smoothing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!