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

How to set the engineering format on a plot axis

55 views
Skip to first unread message

Michel Forte

unread,
Jan 29, 2009, 4:18:02 PM1/29/09
to
The command "format short eng" sets the display format to multiples of 1E0, 1E-3, 1E-6, etc in the command window. How do I force the plot axis numbers to behave the same way ?

someone

unread,
Jan 29, 2009, 4:58:02 PM1/29/09
to
"Michel Forte" <michel...@ultra-tcs.com> wrote in message <glt6ea$qn$1...@fred.mathworks.com>...

> The command "format short eng" sets the display format to multiples of 1E0, 1E-3, 1E-6, etc in the command window. How do I force the plot axis numbers to behave the same way ?

% There is probably a more elegant way,
% but look at num2eng on the MATLAB FEX at:

http://www.mathworks.com/matlabcentral/fileexchange/13168

% Unfortunately, num2eng is not vectorized.
% So, do "something" like:

xstr = get(gca,'XTickLabel'); % get current tick marks (strings)
for ii = 1:length(xstr)
xeng(ii) = num2eng(str2num(xstr(ii)); % convert to engineering strings
end
set(gca,'XTickLabel',xeng) % reset tick marks to engineering notation

% I'm sure there are still some bugs to be worked-out
% in the above code, but this is my first thought.

Michel Forte

unread,
Feb 4, 2009, 3:38:01 PM2/4/09
to
"someone" <som...@somewhere.net> wrote in message <glt8pa$53p$1...@fred.mathworks.com>...

Thank you very much for the answe. I played around for a while, but "get(gca,'XTickLabel')" only gives you the number on the axis without the exponent; also, num2eng does not seem to be recognized by matlab:

??? Undefined function or method 'num2eng' for input arguments of type 'double'.

someone

unread,
Feb 4, 2009, 4:54:01 PM2/4/09
to
"Michel Forte" <michel...@ultra-tcs.com> wrote in message <gmcub9$53l$1...@fred.mathworks.com>...

> "someone" <som...@somewhere.net> wrote in message <glt8pa$53p$1...@fred.mathworks.com>...
> > "Michel Forte" <michel...@ultra-tcs.com> wrote in message <glt6ea$qn$1...@fred.mathworks.com>...
> > > The command "format short eng" sets the display format to multiples of 1E0, 1E-3, 1E-6, etc in the command window. How do I force the plot axis numbers to behave the same way ?
> >
> > % There is probably a more elegant way,
> > % but look at num2eng on the MATLAB FEX at:
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/13168
> >
> > % Unfortunately, num2eng is not vectorized.
> > % So, do "something" like:
> >
> > xstr = get(gca,'XTickLabel'); % get current tick marks (strings)
> > for ii = 1:length(xstr)
> > xeng(ii) = num2eng(str2num(xstr(ii)); % convert to engineering strings
> > end
> > set(gca,'XTickLabel',xeng) % reset tick marks to engineering notation
> >
> > % I'm sure there are still some bugs to be worked-out
> > % in the above code, but this is my first thought.
>
> Thank you very much for the answe. I played around for a while, but "get(gca,'XTickLabel')" only gives you the number on the axis without the exponent;

as it should

> also, num2eng does not seem to be recognized by matlab:
>
> ??? Undefined function or method 'num2eng' for input arguments of type 'double'.

You have to download num2eng from the above link and put it in your MATLAB path.

0 new messages