Add text annotation with variables to matlab plot over multiple lines

36 vues (au cours des 30 derniers jours)
Esme
Esme le 31 Mar 2017
I would like to annotate a plot with a textbox (with or without a visible box) with the following characteristics
  • Use latex as interpreter
  • Have variable inputs (i.e. taken from values within matlab environment)
  • Allow for line breaks where I want them
I have managed to do parts of this, but not all at the same time.
What I have tried:
alpha = 2;
plot(1:10)
text(2,5,'$\alpha = $','Interpreter','latex')
allows me to add the \alpha to the point of interest but I cannot figure out how to also have the variable alpha value
figure
plot(1:10)
dim = [0.179 0.849 0.06 0.037];
str = strcat('\alpha = ',num2str(alpha));
annotation('textbox',dim,'String',str,'FitBoxToText','on','Interpreter','latex');
allows me to include the variable alpha value, but I don't have the latex formatting on \alpha (I presume because of the strcat).
I tried a few suggestions around char(10) and \n to get newlines, but unsuccessfully.
I would appreciate an example of how to annotate this plot (plot(1:10)) with the an annotation that has \alpha = ALPHA on one line and \beta = BETA on the next line where the values for ALPHA and BETA are defined in the code.
Apologies for the basic question, it has been asked many times but I was unable to find a simple example to demonstrate how this worked with all my requirements.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by