Adding Superscript to a string

20 ビュー (過去 30 日間)
Ali
Ali 2013 年 11 月 9 日
コメント済み: Sameed Ahmed 2022 年 2 月 9 日
Hi guys i am new to forums.
my issue is as follows. I have a string to which other strings are concatenated. I want some of them to be in superscript. code is as follows
for i = 1:(length(p)-1)
str = [str,num2str(p(i)), 'X' , (num2str(length(p) -i)), ' + '];
end
i want the portion (num2str(length(p) -i)) to be in superscript but it seems to be posing constant problem as i cannot use the 'abc^{def]' to simply put it in superscript.
any ideas?
  2 件のコメント
Jan
Jan 2013 年 11 月 10 日
Strings are vectors of type char. So they cannot have any superscript properties, because the appearance of the string is controlled by the interpreter. Therefore it matters, where this string should appear.
While the creation and the contents of the string does not matter, it is required to show us the the command you use to display the string.
Ali
Ali 2013 年 11 月 10 日
I use the gtext() command to display the results on to a graph
gtext(str);

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 10 日
Try experimenting with
str = [str, num2str(p(i)), 'X\textsuperscript{', num2str(length(p) -i), '} + '];
  3 件のコメント
Ali
Ali 2013 年 11 月 10 日
str = [str, num2str(p(i)), 'X^{', num2str(length(p) -i), '} + '];
That fixes the problem Thank you walter you gave me the inspiration :D
Sameed Ahmed
Sameed Ahmed 2022 年 2 月 9 日
@Ali your method worked for me. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by