简体   繁体   English

MATLAB:一键直方图矩阵

[英]MATLAB: One-hot matrix to histogram

I have a one-hot-encoded matrix (size 1E6 x 10 ) where each row represents an observation and each column represents a category. 我有一个单一编码的矩阵(大小为1E6 x 10 ),其中每一行代表一个观测值,每一列代表一个类别。 How can I create a histogram to visualize the counts for each category and label the category names in the x-axis (I guess vertically positioned to prevent overlap) rather than just using the column numbers? 如何创建直方图以可视化每个类别的计数并在x轴上标记类别名称(我想垂直放置以防止重叠),而不仅仅是使用列号?

If your matrix is M you can get the row-wise sum, as beaker suggested, and use that to plot a bar chart. 如果矩阵为M ,则可以按照烧杯的建议获得按行求和,然后使用它绘制条形图。 (since you're talking about labels it's unlikely you need a 'histogram' as such). (由于您在谈论标签,因此不太可能需要这样的“直方图”)。

bar (sum (M, 1));

To set the labels to names, you can edit the resulting axes object's properties: 要将标签设置为名称,可以编辑结果轴对象的属性:

set (gca, 'xticklabel', {'one', 'two', 'three', 'four', 'five', 'six'});

If you're using Matlab 2014b or later, you can also control the rotation: 如果您使用的是Matlab 2014b或更高版本,则还可以控制旋转:

set (gca, 'xticklabelrotation', 90);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM