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

    %% Reorder Category Levels in Ordinal Arrays  
% This example shows how to reorder the category levels in an ordinal array
% using |reorderlevels|.   

%% Load sample data. 
AllSizes = {'medium','large','small','small','medium',...
            'large','medium','small'}; 

%%
% The created variable, |AllSizes|, is a cell array of character vectors containing
% size measurements on eight objects.  

%% Create an ordinal array. 
% Convert |AllSizes| to an ordinal array without specifying the order of
% the category levels. 
size = ordinal(AllSizes);
getlevels(size) 

%%
% By default, the categories are ordered by their labels in ascending alphabetical
% order, |large| < |medium| < |small|.  

%% Compare elements. 
% Check whether or not the first object (which has size |medium|) is smaller
% than the second object (which has size |large|). 
size(1) < size(2) 

%%
% The logical value |0| indicates that the medium object is not smaller
% than the large object.  

%% Reorder category levels. 
% Reorder the category levels so that |small| < |medium| < |large|. 
size = reorderlevels(size,{'small','medium','large'});
getlevels(size)  

%% Compare elements. 
% Verify that the first object is now smaller than the second object. 
size(1) < size(2) 

%%
% The logical value |1| indicates that the expected inequality now holds.