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

    %% Create Categorical Array from Integers  

%% 
% Create a 2-by-3 numeric array. 
A = gallery('integerdata',3,[2,3],3) 

%%
% |A| contains the values |1|, |2|, and |3|.  

%% 
% Convert the numeric array, |A|, to a categorical array. Use the values
% |1|, |2|, and |3| to define the categories |car|, |bus|, and |bike|, respectively. 
valueset = 1:3;
catnames = {'car' 'bus' 'bike'};

B = categorical(A,valueset,catnames) 

%%
% |categorical| maps the numeric values in |valueset| to the category names
% in |catnames|. 

%%
% The 2-by-3 categorical array, |B|, is not ordinal. Therefore, you can
% only compare the values in |B| for equality. To compare the values in
% |B| using relational operators, such as less than and greater than, you
% must include the |'Ordinal',true| name-value pair argument.