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!
