Matlab plot text with subscript character
이전 댓글 표시
Dear all, I have been trying to display x label text with subscript. The subscript text contains two numeric or alphanumeric characters. Using '_', it does only first character as in attached figure. However I want all characters after '_' to be subscript. I did not find any clues and or right answers to previous answers. I also tried either of following code. None of them worked.
timescale = 14;
xlabel(['dy_{' int2str(timeScale) '}'], 'Fontsize',16);
or
xlabel(['dy_{' int2str(timeScale) '}'], 'Fontsize',16);
It will be great help to make my figures beautiful. In face same issues happens with supercript and putting 'hat' over the text. I have also attached the figure for your reference.

Thanks in advance
댓글 수: 1
Star Strider
2016년 2월 18일
Both of your code examples worked for me and produced your desired output (in R2015b) so I’m not listing this as an Answer.
If you want to put hats on characters, you need to use the 'Interpreter','latex' option. See the LaTeX site for the necessary documentation on how to write commands to do it. LaTeX is similar to mot more versatile than TeX, with the additional requirement that you have to start and end each LaTeX call with $.
채택된 답변
추가 답변 (3개)
Paul Quinn
2018년 11월 16일
2 개 추천
I have the same problem in 2018a.
Tiffany's answer is the (un-elegant) fix: dy_1_4.
댓글 수: 5
Steven Lord
2018년 11월 16일
I'm using release R2018b, but these should each work in release R2018a as well. With the number hard-coded into the text to be used as the label:
>> xlabel('dy_{14}', 'Interpreter', 'tex')
Below is a version with the number included in the label text. Note that I'm using double quotes and the + operator. This will convert the number into a string and combine it with the other two string arrays dy_{ and }.
>> n = 14;
>> xlabel("dy_{" + n + "}", 'Interpreter', 'tex')
Sofia
2019년 1월 9일
How would you do it for the case where the variable should be interpreted in LaTeX too? For instance, $\Lambda_n$?
Kelly Merckaert
2020년 11월 26일
I have the same question as Sofia.
I can get with the code below
with a varying number for the subscript.
i=1;
ylabel("dotq_{" + i + "} [rad/s]", 'Interpreter', 'tex');
I can with the code below
with a varying number for the subscript.
i=1;
ylabelname = strcat('$\dot{q}$', num2str(i) , '[rad/s]');
ylabel(ylabelname,'fontsize',12,'interpreter','latex');
What I want is a combination of the two, i.e.
, with a varying number for the subscript. How can I get this?
i = 14;
ylabelname = sprintf('$\\dot{q_{%d}}\\,[rad/s]$', i);
ylabel(ylabelname, 'fontsize', 12, 'interpreter', 'latex')
Kelly Merckaert
2020년 12월 8일
That works! Thanks a lot!
Matthias Bohnen
2020년 8월 13일
The same Problem occurs in 2020a.
the code
legend([p1 p2 p3], '$u_{r,rel}$(0d)','$u_{r,rel}$(10d)','$u_{r,rel}$(20d)','Interpreter','Latex');
does succesfully interpretate every letter in parantheses as subscript, but not as Latex, so the $-Signs are shown in the legend and the string is not italic.
You can fix it by writing the code as:
L=legend([p1 p2 p3], '$u_{r,rel}$(0d)','$u_{r,rel}$(10d)','$u_{r,rel}$(20d)');
set(L,'Interpreter','Latex');
And it works!
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
