Effacer les filtres
Effacer les filtres

How to add string and number to a graph?

12 vues (au cours des 30 derniers jours)
Marisabel Gonzalez
Marisabel Gonzalez le 31 Jan 2019
Commenté : Niyi Olukayode le 21 Août 2021
I would like to add the value of the estimated slope to my graph, but I don't know which command to use.
This is what I've tried
% slope
hold on
text(['slope = ',num2str(b)]);
% and
% slope
hold on
txt = ['slope = ',num2str(b)];
text(b,txt,'VerticalAlignment','Cap');
  4 commentaires
Steven Lord
Steven Lord le 31 Jan 2019
Put that information in the title of the axes or as the string in the legend for the line in question?
Adam Danz
Adam Danz le 31 Jan 2019
But what I was actually looking for is the text not depending on any point, sort of as a legend where you can move the box around.
You can move text objects around after they are plotted. Select the "edit plot" arrow, select the text object, and drag it around the screen. But Matlab still needs to know where to initially plot the text so you have to use the x,y inputs to text.
You could put it in the corner of a plot like this
text (min(xlim), max(ylim), 'Upper Left Corner')

Connectez-vous pour commenter.

Réponse acceptée

Jos (10584)
Jos (10584) le 31 Jan 2019
str = 'hello'
gtext(str) % put the text interactively using your mouse

Plus de réponses (0)

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by