www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ChangeCategoryLabelsExample.m
%% Change Category Labels % This example shows how to change the labels for category levels in categorical % arrays using |setlabels|. You also have the option to specify labels when % creating a categorical array. % Copyright 2015 The MathWorks, Inc. %% Load sample data. % The variable |Cylinders| contains the number of cylinders in 100 sample cars. load carsmall unique(Cylinders) %% % The sample has 4-, 6-, and 8-cylinder cars. %% Create an ordinal array. % Convert |Cylinders| to a nominal array with the default category labels % (taken from the values in the data). cyl = ordinal(Cylinders); getlabels(cyl) %% % |ordinal| created labels using the integer values in |Cylinders|, but % you should provide labels for numeric data. %% Change category labels. % Relabel the categories in |cyl| to |Four|, |Six|, and |Eight|. cyl = setlabels(cyl ,{'Four','Six','Eight'}); getlabels(cyl) %% % Alternatively, you can specify category labels when you create a nominal % or ordinal array using the second input argument, for example by specifying % |ordinal(Cylinders,{'Four','Six','Eight'})|.