Documentation Center

  • Trial Software
  • Product Updates

unique

Class: categorical

Unique values in categorical array

The nominal and ordinal array data types might be removed in a future release. To represent ordered and unordered discrete, nonnumeric data, use the MATLAB® categorical data type instead.

Syntax

C = unique(A)
[C,IA,IC] = unique(A)
[...] = unique(A,'rows')
[...] = unique(A,occurrence)
[...] = unique(A,'rows',occurrence)
[...] = unique(...,'legacy')
[...] = unique(A,setOrder)
[...] = unique(A,'rows',setOrder)

Description

C = unique(A) returns a categorical array containing the same values as in A but with no repetitions. C is sorted by the order of A's levels.

[C,IA,IC] = unique(A) also returns index vectors IA and IC such that C = A(IA) and A = C(IC).

[...] = unique(A,'rows') for the categorical matrix A returns the unique rows of A. The rows of the matrix C are sorted by the order of A's levels. The optional outputs IA and IC are index vectors such that C = A(IA,:) and A = C(IC,:).

[...] = unique(A,occurrence) and [...] = unique(A,'rows',occurrence) specify which index is returned in IA in the case of repeated values or rows in A. The default value is occurrence='last', which returns the index of the last occurrence of each repeated value or row in A. occurrence='first' returns the index of the first occurrence of each repeated value or row in A.

[...] = unique(...,'legacy') preserves the pre-2012a behavior of unique. You can specify the flag as the final argument with any previous syntax that accepts A, 'rows', or occurrence.

[...] = unique(A,setOrder) and [...] = unique(A,'rows',setOrder) returns the values or rows of C in a specific order. setOrder='sorted' returns the values or rows of C in sorted order. setOrder='stable' returns the values or rows of C in the same order as A. If A is a row vector, then C is also a row vector. Otherwise, C is a column vector. IA and IC are column vectors. If there are repeated values in A, then IA returns the index of the first occurrence of each repeated value.

See Also

| | | |

Was this topic helpful?