How to write subscript and superscriopt in a single variable?

15 次查看(过去 30 天)
Hello every one,
Can someone tell me how can i write this symbol in matlab script.
  2 个评论
John D'Errico
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
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:

Walter Roberson
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.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by