MATLAB Function Reference Previous page   Next Page
union

Find set union of two vectors

Syntax

Description

c = union(A, B) returns the combined values from A and B but with no repetitions. The resulting vector is sorted in ascending order. In set theoretic terms, c = A B. A and B can be cell arrays of strings.

c = union(A, B, 'rows') when A and B are matrices with the same number of columns returns the combined rows from A and B with no repetitions.

[c, ia, ib] = union(...) also returns index vectors ia and ib such that c = a(ia) b(ib), or for row combinations, c = a(ia,:) b(ib,:). If a value appears in both a and b, union indexes its occurrence in b. If a value appears more than once in b or in a (but not in b), union indexes the last occurrence of the value.

Examples

See Also

intersect, setdiff, setxor, unique, ismember, issorted


Previous page  unicode2native unique Next page

© 1994-2005 The MathWorks, Inc.