MATLAB Function Reference    

Unique elements of a vector



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,m,n] = unique(...) also returns index vectors m and n such that b = A(m) and A = b(n). Each element of m is the greatest subscript such that b = A(m). For row combinations, b = A(m,:) and A = b(n,:).


Because NaNs are not equal to each other, unique treats them as unique elements.

See Also

intersect, ismember, issorted, setdiff, setxor, union

  union unix