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

조회 수: 13 (최근 30일)
Nick DeBarmore
Nick DeBarmore 2013년 1월 31일
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