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

    %% Create Ordinal Categorical Array from Integers  

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

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

%% 
% Convert the numeric array, |A|, to an ordinal categorical array where
% 1, 2, and 3 represent child, adult, and senior respectively. 
valueset = [1:3];
catnames = {'child' 'adult' 'senior'};

B = categorical(A,valueset,catnames,'Ordinal',true) 

%%
% Since |B| is ordinal, the categories of |B| have a mathematical ordering,
% |child < adult < senior|.