{'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
Columns 1 through 6
medium
large
small
small
medium
large
Columns 7 through 8
medium
small
class(sizeOrd)
ans =
'categorical'
The order of the values in the categorical array, sizeOrd, remains unchanged.
List the discrete categories in the categorical variable, sizeOrd.
categories(sizeOrd)
ans = 3x1 cell
{'small' }
{'medium'}
{'large' }
The categories are listed in the specified order to match the mathematical ordering small <
medium < large.
Create Ordinal Categorical Array by Binning Numeric Data
Create a vector of 100 random numbers between zero and 50.
x = rand(100,1)*50;
Create Categorical Arrays
8-3
Précédent

- 307/1450

Suivant