Subscripts in MATLAB Legends
이전 댓글 표시
This is a very basic question, and as my code suggests, it should work, but it's not: I want have the variables in these legend keys have subscripts, but when MATLAB displays the graph, they appear as written with the underscore symbol.
legend('e_1/e_{in}','e_2/e_{in}','e_{out}/e_{in}');
Thanks in advance for your help!
댓글 수: 40
Geoff Hayes
2015년 3월 14일
Quizmaster - the above code works when I try it. If you do
h = legend('e_1/e_{in}','e_2/e_{in}','e_{out}/e_{in}');
and then
get(h,'Interpreter')
what is returned? (The default should be tex.)
N/A
2015년 3월 14일
N/A
2015년 3월 14일
Geoff Hayes
2015년 3월 14일
But what does
get(h,'Interpreter')
return? Is it tex or something else?
N/A
2015년 3월 14일
N/A
2015년 3월 14일
Image Analyst
2015년 3월 14일
The get() function should always work. When get() does not work, what error message does get() throw?
N/A
2015년 3월 14일
Image Analyst
2015년 3월 14일
Can you attach ALL your code, because this is what I get when I try to run the snippet that you included:
Undefined function 'tf' for input arguments of type 'double'.
Error in test1 (line 10)
sys1 = tf(N1,D1);
N/A
2015년 3월 14일
N/A
2015년 3월 14일
Image Analyst
2015년 3월 14일
It looks like you just posted the same code I told you did not work. The function or array tf is not defined for me. What is it? Maybe it's in some toolbox that you forgot to list in the Products section below? It's not in base MATLAB. Or maybe it's some array or function from some part of your code that you forgot to include. I don't know, but I can't run it because tf is not defined for me.
N/A
2015년 3월 14일
N/A
2015년 3월 14일
N/A
2015년 3월 14일
Andrew Newell
2015년 3월 14일
I ran your code several times on 2014a and did not have a problem. You mentioned adding a backslash somewhere - that sounds like a bad idea, since backslashes have a special role in TeX.
N/A
2015년 3월 14일
Mark Hayworth
2015년 3월 14일
I added the Robust Control Toolbox for you to the Products list below. I do not have that toolbox.
Andrew Newell
2015년 3월 14일
This is a long shot, but what answer do you get for
which legend
?
N/A
2015년 3월 14일
N/A
2015년 3월 14일
N/A
2015년 3월 14일
Andrew Newell
2015년 3월 14일
Actually, it might be the Control System Toolbox you're using: the functions tf and bodemag are both in it. Probably the reason ImageAnalyst couldn't run your code is that he doesn't have the toolbox.
N/A
2015년 3월 14일
Andrew Newell
2015년 3월 14일
Since I can't reproduce it in 2014a, my guess is that it is a bug introduced in 2014b. But that's all it is - a guess.
N/A
2015년 3월 14일
Image Analyst
2015년 3월 14일
I doubt it's the problem but you can get the Microsoft Visual C++ Redistributable Packages for Visual Studio 2013 here: http://www.microsoft.com/en-us/download/details.aspx?id=40784 It can't hurt to try.
N/A
2015년 3월 14일
Image Analyst
2015년 3월 14일
Why did you get the old version? Since you're downloading another version why didn't you just get the latest one, R2015a???
N/A
2015년 3월 14일
Image Analyst
2015년 3월 15일
Well I have R2015a and I'm not seeing it, so it maybe something special to your computer. Can you make a generic version, without the tf function, to demonstrate the problem? I'll try it on my computer again.
N/A
2015년 3월 15일
Andrew Newell
2015년 3월 15일
Curious! It looks like the culprit is in bode, but I don't think we'll be able to solve it in this forum. It's time to get Mathworks involved.
N/A
2015년 3월 15일
N/A
2015년 3월 15일
N/A
2015년 3월 16일
Andrew Newell
2015년 3월 16일
Thanks for letting us know the answer. It's good to know there is a workaround.
Lucas Teixeira
2020년 5월 10일
Thanks for sharing !
채택된 답변
추가 답변 (3개)
Ankush Chakrabarty
2017년 12월 11일
6 개 추천
In MATLAB R2016a, the fix seems to be adding a "\_" instead of a "_"
e.g. h = legend('$G\_{\mathrm{a}}$', '$G\_{\mathrm{b}}$'); set(h, 'Interpreter', 'latex');
댓글 수: 1
Arkadeb Sengupta
2020년 9월 27일
This one worked in 2018b too. The other fixes didn't.
Muhammad Sarfraz Mirza
2021년 10월 5일
1 개 추천
TRY this
clc
clear all
a=-360:1:360;
b=sind(a);
c=cosd(a);
plot(a,b)
hold on
plot (a,c)
xlabel('angle in degrees')
ylabel('value of funtion')
title('sin and cos curve')
legend('sin curve','cos curve')
hold off
Image Analyst
2015년 3월 14일
>> doc interpreter
Also, backslash is a special character that sometimes modifies what comes after it, so it's not surprising you get unexpected behavior if you don't know that.
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
