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

    %% Summary of Each Column in Categorical Array  

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

A = categorical(X,valueset,catnames) 

%%
% |A| has three categories, |red|, |green|, and |blue|. The value, |4|,
% was not included in the |valueset| input to the |categorical| function.
% Therefore, the corresponding element, |A(4,1)|, does not have a corresponding
% category and is undefined.  

%% 
% Print a summary of |A|. 
summary(A) 

%%
% |red| appears in one element in the first column of |A| and two in the
% second column. 

%%
% |green| appears in one element in the first column of |A| and none in
% the second column. 

%%
% |blue| appears in one element in the first column of |A| and one in the
% second column. 

%%
% |A| contains only one undefined element. It occurs in the first column.