0
votes

I have a one-hot-encoded matrix (size 1E6 x 10) where each row represents an observation and each column represents a category. 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?

1
Wouldn't the histogram counts just be sum(M, 1)?beaker
Hmm that gives a vector of totals, but not sure how to make a histogram out of that.Austin
given you're talking about 'labels' you don't need a 'histogram', you need a bar chart.Tasos Papastylianou
Ah I guess I should just use bar() thanksAustin

1 Answers

2
votes

If your matrix is M you can get the row-wise sum, as beaker suggested, and use that to plot a bar chart. (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:

set (gca, 'xticklabelrotation', 90);