MATLAB: Does changing XTickLabel change the overall range of the graph axes

axisMATLABrangextickxticklabel

I create a figure and set the 'XTickLabel' property of the axis to be a certain range. When I set the range to [1:1:20], the axis only shows a range of [1:5]. When I change the range to [1:4:20], the axis now shows the proper range of [1:20] with intervals of 4. I want the range to be [1:20] with smaller intervals.

Best Answer

When you set the 'XTickLabel' property, you are setting the text that's associated with the ticks, rather than the values of the ticks.
Consider:
figure(1);clf
bar3(rand(20,30));
set(gca,'XTickLabel',0:20)
get(gca,'XTick')
figure(2);clf
bar3(rand(20,30));
set(gca,'XTickLabel',0:4:20)
get(gca,'XTick')
The values of the ticks are the same in both cases. The 'XTickLabel' only controls the text that appears in the labels (the numbers in 'xAxis' are cast to cell arrays of character vectors).
To set the ticks to be 0:20 or 0:4:20, just set the 'XTick' property. Alternatively use the 'xticks' command.
For more information about controlling various aspects of tick position, label, formatting and rotation, please refer to the link below: