www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CreateCategoricalArrayFromStringArrayExample.m
%% Create Categorical Array from String Array % Starting in R2016b, you can create string arrays using the |string| % function. Convert a string array to a categorical array and then change % its category names. str = string({'plane','jet','plane','helicopter','jet'}) %% C = categorical(str) %% % Specify new category names. When you convert a string array, |valueset| % can be either a string array or a cell array of character vectors. % However, when you specify new category names, you must specify |catnames| % as a cell array of character vectors. valueset = string({'plane','jet','helicopter'}) %% catnames = {'PLN','JET','HEL'} %% % Display the category with new category names. C = categorical(str,valueset,catnames)