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

    %% Category Counts of Each Column in Array  

%% 
% Create a 3-by-2 categorical array, |A|, from a numeric array. 
valueset = 1:3;
catnames = {'red' 'green' 'blue'};

A = categorical([1 3; 2 1; 3 1],valueset,catnames) 

%%
% |A| has three categories, |red|, |green|, and |blue|.  

%% 
% Find the category counts of each column in |A|. 
B = countcats(A) 

%%
% The first row of |B| corresponds to the first category of |A|. The value,
% |red|, occurs once in the first column of |A| and twice in the second column. 

%%
% The second row of |B| corresponds to the second category of |A|. The value,
% |green|, occurs once in the first column of |A|, and it does not occur
% in the second column. 

%%
% The third row of |B| corresponds to the third category of |A|. The value,
% |blue|, occurs once in the first column of |A| and once in the second column.