Adding Superscript to a string

13 vues (au cours des 30 derniers jours)
Ali
Ali le 9 Nov 2013
Commenté : Sameed Ahmed le 9 Fév 2022
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 commentaires
Jan
Jan le 10 Nov 2013
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 le 10 Nov 2013
I use the gtext() command to display the results on to a graph
gtext(str);

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Nov 2013
Try experimenting with
str = [str, num2str(p(i)), 'X\textsuperscript{', num2str(length(p) -i), '} + '];
  3 commentaires
Ali
Ali le 10 Nov 2013
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 le 9 Fév 2022
@Ali your method worked for me. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by