Clear Filters
Clear Filters

how to prolong best fit line to reach to x-axis ?

3 views (last 30 days)
I draw a best fit line
but I want to prolong it to x-axis, how to do this ?
I use this code:
axis([-5 25 0 95]);
grid on
hold on
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 ?

Accepted Answer

Star Strider
Star Strider on 19 Oct 2015
Change the linspace call to:
fittedX = linspace(-coeffs(2)/coeffs(1), max(A), 200);

More Answers (0)


Find more on Graphics Object Programming 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!