Set union of two arrays

returns
the combined data from `C`

= union(`A,B`

)`A`

and `B`

with
no repetitions.

If

`A`

and`B`

are numeric arrays, logical arrays, character arrays, categorical arrays, datetime arrays, duration arrays, or cell arrays of strings, then`union`

returns the combined values from`A`

and`B`

. The values of`C`

are in sorted order.If

`A`

and`B`

are tables, then`union`

returns the combined set of rows from both tables. The rows of table`C`

are in sorted order.

treats
each row of `C`

= union(`A,B`

,'rows')`A`

and each row of `B`

as
single entities and returns the combined rows from `A`

and `B`

with
no repetitions. The rows of `C`

are in sorted order.

The `'rows'`

option does not support cell arrays,
unless one of the inputs is either a categorical array or a datetime
array.

`[`

also returns index vectors `C`

,`ia`

,`ib`

]
= union(`A,B`

)`ia`

and `ib`

.

If

`A`

and`B`

are numeric arrays, logical arrays, character arrays, categorical arrays, datetime arrays, duration arrays, or cell arrays of strings, then the values in`C`

are a sorted combination of the values of`A(ia)`

and`B(ib)`

.If

`A`

and`B`

are tables, then`C`

is a sorted combination of the rows of`A(ia,:)`

and`B(ib,:)`

.

`[`

returns `C`

,`ia`

,`ib`

]
= union(___,`setOrder`

)`C`

in
a specific order using any of the input arguments in the previous
syntaxes. `setOrder='sorted'`

returns the values
(or rows) of `C`

in sorted order. `setOrder='stable'`

returns
the values (or rows) of `C`

in the same order as `A`

,
and then `B`

. If no value is specified, the default
is `'sorted'`

.

Was this topic helpful?