| MATLAB Function Reference | Search  Help Desk |
| unique | Examples See Also |
Syntax
b = unique(a) b = unique(A,'rows') [b,i,j] = unique(...)
Description
b = unique(a)
returns the same values as in a but with no repetitions. The resulting vector is sorted in ascending order. a can be a cell array of strings.
b = unique(A,'rows')
returns the unique rows of A.
[b,i,j] = unique(...)
also returns index vectors i and j such that b = a(i) and a = b(j) (or b = a(i,:) and a = b(j,:)).
Examples
a = [1 1 5 6 2 3 3 9 8 6 2 4] a = 1 1 5 6 2 3 3 9 8 6 2 4 [b,i,j] = unique(a) b = 1 2 3 4 5 6 8 9 i = 2 11 7 12 3 10 9 8 j = 1 1 5 6 2 3 3 8 7 6 2 4 a(i) ans = 1 2 3 4 5 6 8 9 b(j) ans = 1 1 5 6 2 3 3 9 8 6 2 4
See Also
intersect, ismember, setdiff, setxor, union