フィルターのクリア

How to put subscript/superscript in fprintf?

74 ビュー (過去 30 日間)
Waqar Ahmed
Waqar Ahmed 2021 年 1 月 2 日
回答済み: Star Strider 2021 年 1 月 2 日
I want to know how to use subscript and superscript in matlab. For example
fprintf('The optimal dual variable values are \x03bb 1=%0.4f , \x03bb 2=%0.4f ,\x 03bb3=%0.4f \n', l1,l2,l3);
In above \x03bb is unicode for lambda.I want to use 1 2 3 as subscript to lambdas. How can I put subscript to a unicode in matlab

採用された回答

Star Strider
Star Strider 2021 年 1 月 2 日
There is a very limited ability to do that. The ASCII codes for superscripts 1, 2, and 3 are 185, 178 and 179.
You can insert them directly into the format string, or do something like this:
l1 = 3; l2 = 5; l3 = 7;
fprintf('The optimal dual variable values are \x03bb%c=%0.4f , \x03bb%c=%0.4f ,\x03bb%c=%0.4f \n',[185 178 179; l1,l2,l3]);
producing:
The optimal dual variable values are λ¹=3.0000 , λ²=5.0000 ,λ³=7.0000
.

その他の回答 (1 件)

Rik
Rik 2021 年 1 月 2 日
編集済み: Rik 2021 年 1 月 2 日
There are unicode subscript and superscript characters.
disp(char(8320:8329))
You can use these, provided the font contains the glyphs. There are no general options to insert formatting of the output text through fprintf, although many parts of Matlab allow LaTeX formatting.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by