www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CountObservationsInEachLevelExample.m

    %% Count Observations in Each Level
%%
% Create a nominal array from data in a cell array.

colors = nominal({'r','b','g';'g','r','b';'b','r','g'},...
                 {'blue','green','red'})

%%
% Count the number of observations of each level in each column.
levelcounts(colors)

%%
% Count the number of observations of each level in each row.
levelcounts(colors,2)

%%
% Alternatively, you can use |summary| to display the counts with their
% labels. The default is to count elements in each column.
summary(colors)

%%
% You can also count elements in each row.
summary(colors,2)