Documentation |
Set union of two arrays
C = union(A,B) returns the combined data from 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.
C = union(A,B,'rows') treats each row of 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.
[C,ia,ib] = union(A,B) also returns index vectors 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,:).
[C,ia,ib] = union(___,setOrder) returns 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'.