MATLAB Answers

How to display the equation in the graph.Here the slope is found to be 0.35(if i am not wrong) and i want to display the equation as y=0.35x on the graph .Any answers will be highly appreciated

1 view (last 30 days)

Accepted Answer

Mohammad Sami
Mohammad Sami on 4 May 2020
There are two options.
First option is to use the text function to display the text on the axis.
x = -1;
y = -0.5;
text(x,y,'y = 0.35x');
The other option is to use annotations.
x = [0.3 0.5]; % normalized coordinates
y = [0.6 0.5]; % normalized coordinates
annotation('textarrow',x,y,'String','y = 0.35x ')


DEWDROP on 4 May 2020
thanks for your reply but i want to display the equatyion automatically because m may change on the different values
Mohammad Sami
Mohammad Sami on 4 May 2020
you can get the coefficient programatically and convert it to a string.
formula = sprintf('y = %0.4fx',m.Coefficients.Estimate(1));

Sign in to comment.

More Answers (0)