Equation of the Line in command window

I have a graph, with an equation, but i need to display that equation into the command window.

 Risposta accettata

Try this:
B = [y(:) ones(size(y(:)))] \ x(:);
fprintf('Linear: y = %.4f*x%+.2f', B) % Display In Command Window
text(0, max(ylim), sprintf('Linear: y = %.4f*x%+.2f', B), 'HorizontalAlignment','left', 'VerticalAlignment','top') % Display On Plot
.

4 Commenti

I keep getiing an unreconginzable y error
You did not post your variables.
The ‘x’ vector is your independent variable in my code, and ‘y’ is the dependent variable.
If you make the appropriate substitutions, my code should work.
One edit:
B = [y(:) ones(size(y(:)))] \ x(:);
fprintf('Linear: y = %.4f*x%+.2f', B) % Display In Command Window
text(max(0,min(xlim)), max(ylim), sprintf('Linear: y = %.4f*x%+.2f', B), 'HorizontalAlignment','left', 'VerticalAlignment','top') % Display On Plot
That guarantees that the left edge of the text result does not extend beyond the left (y) axis line.
Thank you
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Software Development in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by