categorical.setcats
categorical: B = setcats (A, newcats)
Set categories in categorical array.
B = setcats (A, newcats) sets categories in the
categorical array B according to the elements of the input array
A and the categories specified by newcats according to the
following rules:
newcats can be a string array, a cell array of character vectors
or any type of array that can be converted to a cell array of character
vectors with the cellstr function. When setting a single new
category, newcats can also be specified as a character vector.
Source Code: categorical
setcats replaces the whole category list with the one you give: values that fall outside the new set become <undefined>, and the categories end up as exactly the names you specified (in that order).
C = categorical ({'S'; 'M'; 'L'; 'M'}, {'S', 'M', 'L'})
C =
4x1 categorical array
S
M
L
M
Keep only S and M; the L element is dropped to <undefined>.
setcats (C, {'S', 'M'})
ans =
4x1 categorical array
S
M
<undefined>
M