www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReorderCategoriesinOrdinalCategoricalArrayExample.m
%% Reorder Categories in Ordinal Categorical Array %% % Create an ordinal categorical array, |A|, containing modes of transportation. % Order the categories based on the average price of travel. A = categorical({'plane';'car'; 'train';'car';'plane';'car'},... {'car','train','plane'},'Ordinal',true) %% % |A| is a 6-by-1 ordinal categorical array. %% % Display the categories of |A|. categories(A) %% % Since |A| is ordinal, |car < train < plane|. %% % Reorder the categories to reflect a decrease in the cost of train travel. B = reordercats(A,{'train','car','plane'}) %% % |B| contains the same values as |A|. %% % Display the categories of |B|. categories(B) %% % The mathematical ordering of the categories is now |train < car < plane|. % The results from relational operations, |min|, and |max| reflect the new % category ordering.