使用条形函数时如何在x轴上显示分类数据?

时间:2017-05-10 15:16:15

标签: matlab graph bar-chart matlab-figure axis

我正在尝试模拟官方MATLAB网站上的代码,但我无法获得相同的输出。

这是代码:

line

这是MATLAB网站上的正确输出:

correct output from MatLab website

这是我在MATLAB中得到的输出:

my output from my own MatLab

我的MATLAB输出中未显示c = categorical({'apples','oranges','pears'}); prices = [1.23 0.99 2.3]; bar(c,prices) 数组cappleorange。为什么我没有得到相同的输出?

我的MATLAB版本是R2016a。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下解决方法(如上所述here):

prices = [1.23 0.99 2.3];
bar(prices)
set(gca,'xticklabel',{'apples','oranges','pears'});

所以,你摆脱categorical并切换到gca功能,它允许你改变轴标签。