From: Daniele Bilancione on
Hi everyone!

Is it possible to remove the "x10^y" from the x axis when handling a large variable?

example:

x = zeros(1:220500, 1);
plot(x);
axis([0 length(x) -1 1]);

set(gca, 'XTick', 0:length(x)/10:length(x));

thanks
From: dpb on
Daniele Bilancione wrote:
> Hi everyone!
>
> Is it possible to remove the "x10^y" from the x axis when handling a
> large variable?
>
> example:
>
> x = zeros(1:220500, 1);
> plot(x);
> axis([0 length(x) -1 1]);
>
> set(gca, 'XTick', 0:length(x)/10:length(x));

Maybe not optimum, but...

>> xtik=get(gca,'xtick')*1E5;
>> s=sprintf('%d',xtik(1));
>> for i=2:length(xtik)
>> s=strvcat(s,sprintf('%d',xtik(i)));
>> end
>> set(gca,'xticklabel',s)
>>

Didn't explore whether can retrieve the scale factor; if need be can
derive it, of course it was known here.

--


From: Walter Roberson on
dpb wrote:
> Daniele Bilancione wrote:

>> Is it possible to remove the "x10^y" from the x axis when handling a
>> large variable?

> Maybe not optimum, but...

> >> xtik=get(gca,'xtick')*1E5;
> >> s=sprintf('%d',xtik(1));
> >> for i=2:length(xtik)
> >> s=strvcat(s,sprintf('%d',xtik(i)));
> >> end
> >> set(gca,'xticklabel',s)
> >>

> Didn't explore whether can retrieve the scale factor; if need be can
> derive it, of course it was known here.

The values that are in xtick have not been scaled, and are the full
numeric locations of the tick positions. Rewriting them with scientific
notation is done automatically and only if XTickLabelMode is
'automatic'. As soon as you set an XTickLabel yourself, the scale factor
will be automatically removed.

Thus, the above code should not have the 1E5.

Here is a simpler version of the above code, without any loops:

set(gca, 'XTickLabel', num2str(get(gca, 'XTick')))

If the result doesn't look right, use transpose(get(gca, 'XTick')) [I
can't be bothered at the moment to go in through our VPN to verify
whether the ticks are returned as a row or column vector.]
From: dpb on
Walter Roberson wrote:
> dpb wrote:
>> Daniele Bilancione wrote:
>
>>> Is it possible to remove the "x10^y" from the x axis when handling a
>>> large variable?
>
>> Maybe not optimum, but...
>
>> >> xtik=get(gca,'xtick')*1E5;
>> >> s=sprintf('%d',xtik(1));
>> >> for i=2:length(xtik)
>> >> s=strvcat(s,sprintf('%d',xtik(i)));
>> >> end
>> >> set(gca,'xticklabel',s)
>> >>
>
>> Didn't explore whether can retrieve the scale factor; if need be can
>> derive it, of course it was known here.
>
> The values that are in xtick have not been scaled, and are the full
> numeric locations of the tick positions. ...

You're right, my bad...I was fiddling and added that after posting when
I shouldn'tve...

Good job on eliminating the loop; didn't think of num2str for some
reason... :( (But, I'll claim since it's beautiful spring Sunday
afternoon, _any_ answer is gravy... :) )


--
From: Daniele Bilancione on
dpb <none(a)non.net> wrote in message <hqfkms$gfm$1(a)news.eternal-september.org>...
> Walter Roberson wrote:
> > dpb wrote:
> >> Daniele Bilancione wrote:
> >
> >>> Is it possible to remove the "x10^y" from the x axis when handling a
> >>> large variable?
> >
> >> Maybe not optimum, but...
> >
> >> >> xtik=get(gca,'xtick')*1E5;
> >> >> s=sprintf('%d',xtik(1));
> >> >> for i=2:length(xtik)
> >> >> s=strvcat(s,sprintf('%d',xtik(i)));
> >> >> end
> >> >> set(gca,'xticklabel',s)
> >> >>
> >
> >> Didn't explore whether can retrieve the scale factor; if need be can
> >> derive it, of course it was known here.
> >
> > The values that are in xtick have not been scaled, and are the full
> > numeric locations of the tick positions. ...
>
> You're right, my bad...I was fiddling and added that after posting when
> I shouldn'tve...
>
> Good job on eliminating the loop; didn't think of num2str for some
> reason... :( (But, I'll claim since it's beautiful spring Sunday
> afternoon, _any_ answer is gravy... :) )
>
>
> --

Thank you guys for the swift replies! I did tried to use num2str as I found a post on the forum but didn't work, but I believe I've figured it out:
being an audio sample I would simply need to scale the sequence by the sampling rate, thus:

timex = (0:(length(x)-1))*(1/fs);
plot(timex, x);
axis([0 length(x)*(1/fs) -1 1]);
grid on;

set(gca, 'XTick', round((0:length(x)/10:length(x))*(1/fs)*100)/100);

I don't know whether it's the optimal route to follow or not but it works! :D

Thanks again!!!

kind regards