class(state)
ans =
'categorical'
List the discrete categories in the variable state.
categories(state)
ans = 6x1 cell array
{'CT'}
{'MA'}
{'ME'}
{'NH'}
{'RI'}
{'VT'}
The categories are listed in alphabetical order.
Create Ordinal Categorical Array from Cell Array of Character Vectors
Create a 1-by-8 cell array of character vectors containing the sizes of eight objects.
AllSizes = {'medium','large','small','small','medium',...
'large','medium','small'};
The cell array, AllSizes, has three distinct values: 'large', 'medium', and 'small'.
With the cell array of character vectors, there is no convenient way to indicate that small
< medium < large.
Convert the cell array, AllSizes, to an ordinal categorical array. Use valueset to
specify the values small, medium, and large, which define the categories. For an
ordinal categorical array, the first category specified is the smallest and the last category
is the largest.
valueset = {'small','medium','large'};
sizeOrd = categorical(AllSizes,valueset,'Ordinal',true)
sizeOrd = 1x8 categorical array
Columns 1 through 6
medium large small small medium large
Create Categorical Arrays