How can I combine variables with LaTex strings in a plot annotation?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an integer variable, phi. I want to display "phi = myvariable" on the plot. I think it is not working because I am mixing interpretable strings with variables in an incorrect manner.
I've posted the code below, followed by the Warnings that are generated.
Thanks in advance for you help.
close
%Define functions
x = -3.0:0.01:3.0;
f = x.^2;
g = 5*sin(x) + 5;
% Plot function f
figure;
plot(x, f, 'r-', 'LineWidth', 2);
%Annotate the plot to display phi = (var:phi)
annotation('textbox',[.63 .25 .1 .2],'String',['$\phi = $' num2str(phi)],'interpreter','latex','BackgroundColor','white')
Warning: Unable to interpret LaTeX string "$\phi" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi =" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$0.453" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi =$0.453" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 461 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi =" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$0.453" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 456 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi =$0.453" > In scribe.textbox.createTextBox>localGetStrSize at 568 In scribe.textbox.createTextBox>localResizeText at 461 In scribe.textbox.createTextBox>localChangePosition at 337 In scribe.scribeobject.createScribeObject>localUpdatePosition at 48 Warning: Unable to interpret LaTeX string "$\phi =$0.453"
1 commentaire
Kye Taylor
le 16 Avr 2013
Modifié(e) : Kye Taylor
le 16 Avr 2013
In your code, phi is not defined. I can run your code and get a label like you'd expect, if I add a line like phi = 2;
What is your output from
which phi
Réponses (1)
Sathish Kumar
le 16 Avr 2013
Add a space after the second $ symbol in '$\phi=$'...... Actually no latex compiler can understand $\phi=$1234.... You have to form $\phi=$ 1234 for the latax compiler to understand.(The space between the second $ and the number is important.
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!