MATLAB Functions Help Desk

union

Purpose

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.

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) and c = b(ib) or, for row combinations, c = a(ia,:) and
c = b(ib,:).

A nonvector input array A is regarded as a column vector A(:).

Examples

See Also

intersect   Set intersection of two vectors

setdiff     Return the set difference of two vectors

setxor      Set exclusive-or of two vectors

unique      Unique elements of a vector



[ Previous | Help Desk | Next ]