How can I use subscript from html in Matlab? Please help.

<p>My first<sub>html </sub> paragraph.</p>

3 Comments

What is your question? What do you want to do?
Have a read here and here. It will greatly improve your chances of getting an answer.
Hello Rik, thank you for the reply. Actually I have searched a lot to be able to write a string in Matlab that small part of it be in subscript form. Now I am trying to extract subscript form of the following html code in Matlab. I do not want to call html file in Matlab in that case I do not know how extract just one paragraph in html that has converted my string to subscript form.
str= '<p>The chemical formula of water: H<sub>2</sub>O</p>';
s = regexprep(str, '<.*?>','')
Again this code gives me whole string without converting it to subscript. How can I fix this code in Matlab to have H2O in subscript form? I would appreciate it it you help me to find a way to write subscript in Matlab. Thank you.
What, exactly, would be your desired output given that str ?

Sign in to comment.

Answers (1)

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 Comments

Thank you Rik, but I want something like this in string not figure.
B= {'The hight,M_crly:', M};
C={'The length,W_x:', W};
Actually, I want to write crly and x in subscript form in Matlab that is not in figure. It is just name of variable. I would appreciate it if you let me know if there is any char values as you told me about these. Also, I need to write \phi (in Latex we write like this) again in the same way. Is there any way to write Latex command in Matlab but not in figure or plot for just simple name of variable? Can you please provide me with the link that has equivalent numbers for especial characters?
I thought that I can write subscript in html and extract data in Matlab but I do not know how extract subscripted form. Is there any way for example using dom object of Matlab to write these subscripted ones in Latex in Matlab for simple string not plot? I have seen if I use power point object we can do subscript but not for creating pdf or doc.
I highly appreciate your time.
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.
Hello Walter, I see there is a misunderstanding in my explanation about variable. I just want to have a string that has subscript font in some characters.
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.
Thanks for your help and time.

Sign in to comment.

Categories

Asked:

on 27 Jul 2017

Commented:

on 3 Aug 2017

Community Treasure Hunt

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

Start Hunting!