www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReorderCategoriesinNonordinalCategoricalArrayExample.m
%% Reorder Categories in Nonordinal Categorical Array %% % Create a categorical array containing the color of various items. A = categorical({'red';'green';'blue';'red';'green';'red';'blue';'blue'}) %% % |A| is an 8-by-1 categorical array. %% % Display the categories of |A|. categories(A) %% % The categories of |A| are in alphabetical order and have no mathematical % meaning. %% % Reorder the categories to match the order commonly used for colors. B = reordercats(A,{'red','green','blue'}) %% % |B| contains the same values as |A|. %% % Display the categories of |B|. categories(B) %% % |B| is not ordinal and the order of the categories has no mathematical % meaning. Although the categories appear in the order of the color spectrum, % relational operations, such as greater than and less than, have no meaning.