www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/MergeCategoriesofOrdinalCategoricalArrayExample.m
%% Merge Categories of Ordinal Categorical Array %% % Create an ordinal categorical array. A = categorical([1 2 3 2 1],1:3,{'poor','fair','good'},'Ordinal',true) %% % Display the categories of |A|. categories(A) %% % Since |A| is ordinal, the categories have the mathematical ordering |poor % < fair < good|. %% % Consider all |fair| or |poor| values to be |bad|. Since |A| is ordinal, % the categories to merge must be consecutive. B = mergecats(A,{'fair' 'poor'},'bad') %% % The value |bad| replaces all instances of |fair| and |poor|. %% % Display the categories of |B|. categories(B) %% % |B| has two categories with the mathematical ordering: |bad < good|.