| MATLAB Function Reference | Search  Help Desk |
| union | Examples See Also |
c = union(a,b) c = union(A,B,'rows') [c,ia,ib] = union(...)
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) and c = b(ib) or, for row combinations, c = a(ia,:) and c = b(ib,:).
a = [-1 0 2 4 6];
b = [-1 0 1 3];
[c,ia,ib] = union(a,b);
c =
-1 0 1 2 3 4 6
ia =
3 4 5
ib =
1 2 3 4
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