Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Amr Hashem
Amr Hashem am 19 Okt. 2015
Kommentiert: Star Strider am 20 Okt. 2015
I draw a best fit line
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 ?

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by