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

    %% Create Categorical Array from Character Vectors  
% Convert a cell array of character vectors to a categorical array.   

%% 
% Create a cell array of character vectors. 
A = {'r' 'b' 'g'; 'g' 'r' 'b'; 'b' 'r' 'g'} 

%%
% |A| is a 3-by-3 cell array containing three unique values.  

%% 
% Convert the cell array of character vectors, |A|, to a categorical array, |B|. 
B = categorical(A) 

%%
% The contents of |B| match the contents of |A|.  

%% 
% Display the categories of |B|. 
categories(B) 

%%
% The categories of |B| are the unique values from |A| in alphabetical order.