How can I combine variables with LaTex strings in a plot annotation?

14 Ansichten (letzte 30 Tage)
Nick DeBarmore
Nick DeBarmore am 31 Jan. 2013
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 Kommentar
Kye Taylor
Kye Taylor am 16 Apr. 2013
Bearbeitet: Kye Taylor am 16 Apr. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sathish Kumar
Sathish Kumar am 16 Apr. 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.

Community Treasure Hunt

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

Start Hunting!

Translated by