How to write subscript and superscriopt in a single variable?

조회 수: 20 (최근 30일)
vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020년 3월 13일
답변: Walter Roberson 2024년 12월 3일
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.
vishnuvardhan naidu tanga
vishnuvardhan naidu tanga 2020년 3월 13일
Dear John D'Errico,
thank you so much for the reply.

댓글을 달려면 로그인하십시오.

답변 (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에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by