B = categorical([2;1;1;2;2],1:2,{'xsmall','small'},'Ordinal',true)
B = 5x1 categorical
small
xsmall
xsmall
small
small
B is a 5-by-1 categorical array with two categories such that xsmall < small.
To combine two ordinal categorical arrays (which always have protected categories), they must have
the same categories and the categories must be in the same order.
Add the category 'xsmall' to A before the category 'small'.
A = addcats(A,'xsmall','Before','small');
categories(A)
ans = 5x1 cell
{'xsmall'}
{'small' }
{'medium'}
{'large' }
{'xlarge'}
Add the categories {'medium','large','xlarge'} to B after the category 'small'.
B = addcats(B,{'medium','large','xlarge'},'After','small');
categories(B)
ans = 5x1 cell
{'xsmall'}
{'small' }
{'medium'}
{'large' }
{'xlarge'}
The categories of A and B are now the same including their order.
Vertically concatenate A and B.
C = [A;B]
C = 15x1 categorical
medium
xlarge
small
small
medium
large
medium
large
medium
8 Categorical Arrays
8-32
B = 5x1 categorical
small
xsmall
xsmall
small
small
B is a 5-by-1 categorical array with two categories such that xsmall < small.
To combine two ordinal categorical arrays (which always have protected categories), they must have
the same categories and the categories must be in the same order.
Add the category 'xsmall' to A before the category 'small'.
A = addcats(A,'xsmall','Before','small');
categories(A)
ans = 5x1 cell
{'xsmall'}
{'small' }
{'medium'}
{'large' }
{'xlarge'}
Add the categories {'medium','large','xlarge'} to B after the category 'small'.
B = addcats(B,{'medium','large','xlarge'},'After','small');
categories(B)
ans = 5x1 cell
{'xsmall'}
{'small' }
{'medium'}
{'large' }
{'xlarge'}
The categories of A and B are now the same including their order.
Vertically concatenate A and B.
C = [A;B]
C = 15x1 categorical
medium
xlarge
small
small
medium
large
medium
large
medium
8 Categorical Arrays
8-32
