How to write subscript and superscriopt in a single variable?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
vishnuvardhan naidu tanga
el 13 de Mzo. de 2020
Respondida: Walter Roberson
el 3 de Dic. de 2024
Hello every one,
Can someone tell me how can i write this symbol in matlab script.

2 comentarios
John D'Errico
el 13 de Mzo. de 2020
Sorry. You cannot have a variable name with either subscripts or superscripts, so certainly not both. Are you asking how to use Latex to create something of the sort, perhaps in a published file or live script, but essentially as a comment?
If you insist on a variable name that contains that information, I might suggest that you insert underscore characters in the name. Thus, perhaps C_2_CH3OH.
Respuestas (2)
Shlok
el 3 de Dic. de 2024
Hi Vishnuvardhan,
To store a formula consisting of superscript and nested subscripts, the approach is to store it as a string with LaTeX formatting and use it with the LaTeX interpreter. Here is a sample code:
formula = '$C^{2}_{CH_3OH}$';
title(formula, 'Interpreter', 'latex');
In this example, ‘^’ denotes superscript, and ‘_’ denotes subscript. Curly braces ‘{}’ are used for grouping elements within the formula. Note that LaTeX-formatted strings can be viewed in the Live Editor and figures, but not in the console.
To know more about adding LaTeX formatting in Live Editor, refer to the following MathWorks documentation:
0 comentarios
Walter Roberson
el 3 de Dic. de 2024
You can create symbolic variable names that are specially formatted. When expressions using those names are displayed in LiveScript (but not at the command window!) then the variables will be formatted.
Unfortunately, the formatting is restricted to one level of superscripts and subscripts, and to character ornations such as bars and hats. The formatting does not extend to being able to subscript the 3 on the
while inside the
construct. And the formatting unfortunately does not allow for
--- after the base name, everything has to be subscript or superscript.



syms C__2_CH3OH
C__2_CH3OH
Sadly, at the moment the display of formatted symbolic output is broken, so at the moment you would not be able to see the
output.

0 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!