Skip to Main Content Skip to Search
Product Documentation

hist - Class: categorical

Plot histogram of categorical data

Syntax

hist(Y)
hist(Y,X)
hist(ax,...)
N = hist(...)
[N,X] = hist(...)

Description

hist(Y) plots a histogram bar plot of the counts for each level of the categorical vector Y. If Y is an m-by-n categorical matrix, hist computes counts for each column of Y, and plots a group of n bars for each categorical level.

hist(Y,X) plots bars only for the levels specified in X. X is a categorical vector or a cell array of level names as strings.

hist(ax,...) plots into the axes with handle ax instead of gca.

N = hist(...) returns the counts for each categorical level. If Y is a matrix, hist works down the columns of Y and returns a matrix of counts with one column for each coluimn of Y and one row for each cetegorical level.

[N,X] = hist(...) returns the categorical levels corresponding to each count in N, or corresponding to each column of N if Y is a matrix.

Examples

Create a histogram of age groups from the hospital.mat dataset:

load hospital
edges = 0:10:100;
labels = strcat(num2str((0:10:90)','%d'),{'s'});
AgeGroup = ordinal(hospital.Age,labels,[],edges);
AgeGroup = droplevels(AgeGroup);
hist(AgeGroup)

See Also

categorical.getlevels | categorical.levelcounts | hist

  


 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS