【发布时间】:2018-04-22 20:11:24
【问题描述】:
我创建了一个分类直方图:
h = histogram( categorical( emotions{startIndex:endIndex,:} ) )
h.Categories
ans =
1×5 cell array
{'ANGER'} {'CONTEMPT'} {'DISGUST'} {'JOY'} {'SADNESS'}
>> h.Values
ans =
164 26 18 191 1
但似乎没有办法在直方图条上显示标签(即h.Values)。
在this post之后,我尝试了这个:
text(h.Values, h.Categories, num2str(h.Values'), 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom' );
但我只是得到:
错误使用文本前两个或三个参数必须是数字双精度。
但问题是我的x 值永远不会是数字,它们是分类的。如何解决?
对于一个可重现的示例,可以这样做:
emotions = { 'JOY','JOY','JOY','JOY','JOY','JOY','JOY','JOY','JOY','JOY','ANGER','ANGER','CONTEMPT','CONTEMPT','CONTEMPT','JOY','ANGER','ANGER','ANGER','ANGER'}
emotions = emotions.';
t = cell2table(emotions)
histogram(categorical(emotions))
【问题讨论】:
标签: matlab histogram matlab-figure categorical-data