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

    %% Merge Alphabetically Listed Categories  

%% 
% Create a categorical array containing various items. 
A = categorical({'shirt' 'pants'; 'shoes' 'shirt'; 'dress' 'belt'})  

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

%%
% The five categories are in alphabetical order.  

%% 
% Merge the categories |belt| and |shoes| into a new category called |other|. 
B = mergecats(A,{'belt' 'shoes'},'other') 

%%
% The value |other| replaces all instances of |belt| and |shoes|.  

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

%%
% |B| has four categories and the order is no longer alphabetical. |other|
% appears in place of |belt|.