How to make exponents superscripted on plots instead of with e notation?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
zero1342
le 1 Juil 2015
Modifié(e) : Muthu Annamalai
le 23 Juil 2015
I am displaying a variable in the title of a plot but I would like it to show with the exponent part superscripted instead of in the e notation. For example:
n0=10^25
plot(...)
title('n0')
This displays n0 as 1.0e+25 in the title instead of the 25 superscripted. Is there a way to do this in MATLAB without having to manually type a new string into the title every time?
I don't want to have to do this:
title('10^{25}')
Thanks for any help.
0 commentaires
Réponse acceptée
Plus de réponses (1)
Muthu Annamalai
le 1 Juil 2015
Whereas some options may exist, a simple work around does the trick following your hint;
var2exp = @( varname, var ) [regexprep(sprintf('%s=%g',varname,var),'[e|E]','^{'),'}']
title(var2exp('n0',n0))
this is admittedly kludgy, but seems to suit your needs.
2 commentaires
Muthu Annamalai
le 23 Juil 2015
Modifié(e) : Muthu Annamalai
le 23 Juil 2015
I'm not so sure.
Whereas my code will work for -ve numbers, your code may fail, and badly at that with some complex output for log10 of a 0 or -ve number.
Voir également
Catégories
En savoir plus sur Title 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!