How to write subscript and superscriopt in a single variable?
16 ビュー (過去 30 日間)
古いコメントを表示
Hello every one,
Can someone tell me how can i write this symbol in matlab script.

2 件のコメント
John D'Errico
2020 年 3 月 13 日
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.
回答 (2 件)
Shlok
2024 年 12 月 3 日
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 件のコメント
Walter Roberson
2024 年 12 月 3 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!