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

11 次查看(过去 30 天)
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 个评论
Kye Taylor
Kye Taylor 2013-4-16
编辑:Kye Taylor 2013-4-16
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

请先登录,再进行评论。

回答(1 个)

Sathish Kumar
Sathish Kumar 2013-4-16
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.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by