Ordinal Categorical Array from a Cell Array of Character Vectors
Create an ordinal categorical array, sizes, from a cell array of character vectors, A. Use
valueset, specified as a vector of unique values, to define the categories for sizes.
A = {'medium' 'large';'small' 'medium'; 'large' 'small'};
valueset = {'small', 'medium', 'large'};
sizes = categorical(A,valueset,'Ordinal',true)
sizes = 3x2 categorical array
medium large
small medium
large small
sizes is 3-by-2 ordinal categorical array with three categories such that small <
medium < large. The order of the values in valueset becomes the order of the
categories of sizes.
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 array
medium large
small medium
large small
Compare sizes and sizes2
isequal(sizes,sizes2)
ans = logical
1
Ordinal Categorical Arrays