How to change the axis on a chart without changing the data

8 views (last 30 days)
I have a bar graph that shows data for bins ranging 0 to 16. Because matlab doesn't allow indexing of 0, the index for the 0 bin is 1, the index for the 1 bin is 2, ect.
How can I change the labels on the axis on the graph to reflect the ACTUAL data instead of the indices? I have tried to follow the example for gca.XTickLabel but it didn't change anything.

Answers (1)

Star Strider
Star Strider on 17 Jul 2015
You have to define both 'XTick' and 'XTickLabel' when you want to use 'XTickLabel'. If you just want to number the bars though, 'XTick' alone is enough:
data = randi(10, 1, 16); % Create Data
figure(1)
bar(data)
set(gca, 'XTick', [1:16])

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!