categorical.removecats
categorical: B = removecats (A)
categorical: B = removecats (A, oldcats)
Remove categories from categorical array.
B = removecats (A) removes all unused categories from
categorical array A. The output categorical array B has the
same size and values as A, but potentially fewer categories.
B = removecats (A, oldcats) removes the
categories specified by oldcats. The elements of B that
correspond to the removed categories are undefined.
oldcats 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. Any names in oldcats
that do not reference an existing category are ignored.
When removing a single category, oldcats can also be specified as a character vector.
Source Code: categorical
removecats drops categories from an array.
C = categorical ({'S'; 'M'; 'S'}, {'S', 'M', 'L'})
C =
3x1 categorical array
S
M
S
Naming a category removes it and turns its elements into <undefined>.
removecats (C, 'M')
ans =
3x1 categorical array
S
<undefined>
S
With no list only the unused categories go (values unchanged) — here the unused L disappears from the category list.
categories (removecats (C))
ans =
2x1 cell array
{'S'}
{'M'}