Friday, April 01, 2005

Getting Around Matlab's Axes Formatting

Matlab likes to format your axes into scientific notation whenever the numbers are large or small. There doesn't seem to be any quick way to turn this off-- the axes labeling is unaffected by 'format' or anything like that. Luckily, the axis object contains both the raw floating point values of the tick marks and also an array of strings that Matlab automatically creates. What you can do is this:

numericticks=get(gca,'XTick'); % get the values of the ticks
fullticks = num2str(numericticks','%7.0f'); % save as strings
set(gca,'XTickLabel',fullticks); % set the text labels to force
% MATLAB not to use scientific
% notation


This gets the tick values of the X axis of the current axes. It then converts them to strings and updates the string array in the axis object, overwriting the Matlab generated ones. Just set the formatting string in the call to num2str for you needs. Note that the matrix numericticks needs to be transposed in this call otherwise Matlab flips out when you set the tick labels.

No comments:

Labels

Blog Archive

Contributors