how to prolong best fit line to reach to x-axis ?
조회 수: 1 (최근 30일)
이전 댓글 표시
I draw a best fit line
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150563/image.jpeg)
but I want to prolong it to x-axis, how to do this ?
I use this code:
figure;
h=bar(val,n,'b');
axis([-5 25 0 95]);
grid on
hold on
A=[1;17];
B=[16;92];
plot(A, B, 'go')%, 'LineWidth', 1, 'MarkerSize', 10);
coeffs = polyfit(A, B, 1);
fittedX = linspace(min(A), max(A), 200);
fittedY = polyval(coeffs, fittedX);
plot(fittedX, fittedY, 'r-', 'LineWidth', 3);
how to prolong the best fit line ?
댓글 수: 0
채택된 답변
Star Strider
2015년 10월 19일
Change the linspace call to:
fittedX = linspace(-coeffs(2)/coeffs(1), max(A), 200);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!