categorical.union
categorical: C = union (A, B)
categorical: C = union (A, B, 'rows')
categorical: [C, ixA, ixB] = union (…)
categorical: … = union (…, order)
Set union of two categorical arrays.
C = union (A, B) returns the unique common
values of the categorical arrays A and B. Either A or
B input arguments may be a character vector, a string array, or a
cell array of character vectors, which is promoted to a categorical array
prior to set exclusive-or. If both A and B are row vectors,
then C is also a row vector, otherwise union returns a
column vector.
If categorical arrays A and B are ordinal, they must have the same set and ordering of categories, which is transfered to C. If neither are ordinal, the category names of each pair of elements are compared (they do not need to have the same set of categories) in which case the categories in C are the sorted union of the categories in A and B.
C = union (A, B, returns the
unique common rows of the categorical matrices A and B, which
must have the same number of columns. By default, the rows in
categorical matrix C are in sorted order.
'rows'
[C, ixA, ixB] = union (…) also returns
index vectors ixA and ixB such that
C = A(ixA) and
C = B(ixB), unless the 'rows' optional
argument is given, in which case C = A(ixA,:)
and C = B(ixB,:).
… = union (…, order) also specifies the
order of the returned unique values. order may be either
'sorted', which is the default behavior, or 'stable',
in which case the unique values are returned in order of appearance.
Source Code: categorical
union returns the distinct values present in either array — the set union.
A = categorical ({'S'; 'M'; 'L'})
A =
3x1 categorical array
S
M
L
B = categorical ({'M'; 'L'; 'XL'})
B =
3x1 categorical array
M
L
XL
union (A, B)
ans =
4x1 categorical array
L
M
S
XL