How can I use subscript from html in Matlab? Please help.
Afficher commentaires plus anciens
<p>My first<sub>html </sub> paragraph.</p>
3 commentaires
Walter Roberson
le 28 Juil 2017
What, exactly, would be your desired output given that str ?
Réponses (1)
Rik
le 28 Juil 2017
If you want to use subscript in axis labels and things like that, Matlab has a LaTeX interpreter, so you can input the string as below. (you can do multiple characters with _{} and superscript with ^{})
str='The chemical formula of water: H_2O';
Otherwise, as you may infer from the html, subscript is only a markup thing; there is nothing inherently subscript about is. There are some exceptions, as some special characters are hardcoded. For example ² is char(178).
In fact, the subscript 2 happens to be a special case as well, so char(8322) will get you that character.
str=strcat('The chemical formula of water: H',char(8322),'O');
plot(rand(10,1))
title(str)
7 commentaires
Sorayya
le 28 Juil 2017
Modifié(e) : per isakson
le 31 Juil 2017
Walter Roberson
le 28 Juil 2017
Variable names must start with a Latin letter, A-Z or a-z, and after that must be followed only by the Latin letters, or the arabic digits 0-9 or underscore ('_') . It is not possible to have a variable that includes a subscript or that is a greek phi.
Sorayya
le 28 Juil 2017
Walter Roberson
le 28 Juil 2017
As Rik explained, there are only a limited number of characters that have subscript form, like char(8322) . There is no subscript "c" or "r" or "l" or "y" characters in Unicode.
Your question is like asking for a string to have colored characters in it, or characters from special fonts: colors and fonts and (general) subscripting or superscripting is a matter of presentation, not something that can be stored as character attributes in Unicode.
This is why I asked a few times about the circumstances under which the subscript needs to show up as a subscript. You will not be able to do this for strings being displayed at the command prompt or in the variable viewer. You will not be able to do this for characters stored in a plain text file. You can do it for strings being plotted by text(), by using a TeX or LaTeX interpreter option. You cannot do it for strings going into uicontrol of style edit or style text. You can do it for strings going into some of the other uicontrol varieties such as radiobutton . You can do it for strings going into uitable() -- but if the user asks to edit the cell they will see the messy code needed to produce the output rather than direct characters.
Sorayya
le 31 Juil 2017
Walter Roberson
le 31 Juil 2017
Actually, coloring strings to be displayed in the command window is possible to some extent; https://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-the-command-window
Sorayya
le 3 Août 2017
Catégories
En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!