www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReorderCategorieswithNumericVectorExample.m
%% Reorder Categories with Numeric Vector %% % Create a categorical array, |A|, containing modes of transportation. A = categorical({'plane';'car';'train';'car';'car';'plane';'car'}) %% % Display the categories of |A|. categories(A) %% % Reorder categories from least to most frequent occurrence in |A|. B = countcats(A); [C,neworder] = sort(B); neworder %% D = reordercats(A,neworder); categories(D) %% % Because |countcats| counts the occurrences of each category, |neworder| % describes how to reorder the categories—not the elements—of |A|.