Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sub / Superscript using sprintf

398 views
Skip to first unread message

Jonathan

unread,
May 3, 2009, 5:09:02 AM5/3/09
to
I want to display text to the used in the command window so i am using sprintf.
How can i get use sub and superscripts using this method or is there a better way?

Thank you

Tim

unread,
Oct 13, 2011, 10:35:15 PM10/13/11
to
"Jonathan" <no...@domain.com> wrote in message <gtjmve$o3s$1...@fred.mathworks.com>...

> I want to display text to the used in the command window so i am using sprintf.
> How can i get use sub and superscripts using this method or is there a better way?
>
> Thank you

Jonathan - your question is not very clear. I came across your post when I was looking for tips on how to make sprintf display superscripts and subscripts of variables and strings as part of axis labels. In the example below, I make an xy plot and then demonstrate how to do this. I hope this helps.

Cheers,

Tim

d='demo' % this is a string and will be the subscript associated with the x-axis label
p=0.5; % this is a numeric it is used to create vector y and used as a superscript in the y-axis label.
x=1:2:100;
y=x.^p;
plot(x,y,'.')
ylabel(sprintf('y=x^{%0.4g}',p )) % caret and brackets = superscript
xlabel(sprintf('x_{%s}',d)) % underscore and brackets = subscript

0 new messages