Ordinal Categorical Array from Integers
Create an equivalent categorical array from an array of integers. Use the values 1, 2, and 3 to define
the categories small, medium, and large, respectively.
A2 = [2 3; 1 2; 3 1];
valueset = 1:3;
catnames = {'small','medium','large'};
sizes2 = categorical(A2,valueset,catnames,'Ordinal',true)
sizes2 = 3x2 categorical
medium
large
small
medium
large
small
Compare sizes and sizes2
isequal(sizes,sizes2)
ans = logical
1
sizes and sizes2 are equivalent categorical arrays with the same ordering of categories.
Convert a Categorical Array from Nonordinal to Ordinal
Create a nonordinal categorical array from the cell array of character vectors, A.
sizes3 = categorical(A)
sizes3 = 3x2 categorical
medium
large
small
medium
large
small
Determine if the categorical array is ordinal.
isordinal(sizes3)
ans = logical
0
sizes3 is a nonordinal categorical array with three categories, {'large','medium','small'}.
The categories of sizes3 are the sorted unique values from A. You must use the input argument,
valueset, to specify a different category order.
Convert sizes3 to an ordinal categorical array, such that small < medium < large.
sizes3 = categorical(sizes3,{'small','medium','large'},'Ordinal',true);
Ordinal Categorical Arrays
8-37
Précédent

- 341/1450

Suivant