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
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.
--
>> 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.]
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
I tried the command:
set(gca,'XTickLabel',num2str(get(gca,'XTick').'))
and I have a warning:
While zooming or panning the xtick numbers change byt xtick labels do not. Be aware!
"Simon " <simon....@epsilon.nu> wrote in message
news:ijgh08$753$1...@fred.mathworks.com...
That's correct -- to have the labels change as well use the
ActionPostCallback of the zoom mode or pan mode object to change them.
http://www.mathworks.com/help/techdoc/ref/zoom.html
http://www.mathworks.com/help/techdoc/ref/pan.html
--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com