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

    %% Category Counts of Categorical Vector  

%% 
% Create a 1-by-5 categorical vector. 
A = categorical({'plane' 'car' 'train' 'car' 'plane'}) 

%%
% |A| has three categories, |car|, |plane|, and |train|.  

%% 
% Find the number of elements in each category of |A|. 
B = countcats(A) 

%%
% The first element in |B| corresponds to the first category of |A|, which
% is |car|. The second element in |B| corresponds to the second category
% of |A|, which is |plane|. The third element of |B| corresponds to the
% third category of |A|, which is |train|. 

%%
% Since |A| is a row vector, |countcats| returns a row vector.