Filter löschen
Filter löschen

Matlab plot text with subscript character

635 Ansichten (letzte 30 Tage)
Mahesh
Mahesh am 18 Feb. 2016
Bearbeitet: Walter Roberson am 8 Dez. 2020
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 Kommentar
Star Strider
Star Strider am 18 Feb. 2016
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 $.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Paul Quinn
Paul Quinn am 16 Nov. 2018
Yes, Steven Lord's answer works for me in 2018a.

Weitere Antworten (3)

Tiffany Calcutt
Tiffany Calcutt am 29 Okt. 2017
'dy_1_4'

Paul Quinn
Paul Quinn am 16 Nov. 2018
I have the same problem in 2018a.
Tiffany's answer is the (un-elegant) fix: dy_1_4.
  5 Kommentare
Walter Roberson
Walter Roberson am 26 Nov. 2020
Bearbeitet: Walter Roberson am 8 Dez. 2020
i = 14;
ylabelname = sprintf('$\\dot{q_{%d}}\\,[rad/s]$', i);
ylabel(ylabelname, 'fontsize', 12, 'interpreter', 'latex')
Kelly Merckaert
Kelly Merckaert am 8 Dez. 2020
That works! Thanks a lot!

Melden Sie sich an, um zu kommentieren.


Matthias Bohnen
Matthias Bohnen am 13 Aug. 2020
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!

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by