How can I specify the precision of the tick labels on an axis in MATLAB 7.3 (R2006b)?
11 views (last 30 days)
Show older comments
I would like to be able to specify the displayed precision of the tick label.
Accepted Answer
MathWorks Support Team
on 27 Dec 2012
The ability to specify the precision of the tick labels on an axis is not available in MATLAB 7.3 (R2006b).
To work around this issue, you can retrieve the ticks, convert them to strings with a specified precision, and set the labels to the new tick labels. The following example code can be executed at the MATLAB command prompt, to illustrate this work around:
% Create an example plot.
plot(1:10);
% Query xTick numerical values.
xTick = get(gca,'xTick');
% Create strings out of xTick numerical values with a prescribed precision.
% The format string '%a.bf' means to present the values within a field that
% is wide enough to fit 'a' digits with 'b' digits after the decimal point
% in the format of a 'f'loating point number.
xTickLabel = arrayfun( ... % arrayfun maps a function onto each member of a cell, one at a time.
@(x) sprintf('%3.2f',x), ... % Anonymous function acting on each element of xTick.
xTick, ...
'uniformoutput', false); % Option to arrayfun to deal with multiple outputs.
% Use xTickLabel on the plot.
set(gca, 'xTickLabel', xTickLabel);
Note that once the tick labels have been set, they are in manual mode. The tick labels will not update automatically with the resizing of the figure window or zooming in and out of the window.
0 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!