C = unique(A)
C = unique(A, 'rows')
C = unique(A, 'stable')
C = unique(A, 'first')
C = unique(A, 'last')
C = unique(A, 'legacy')
C = unique(A, 'rows', 'legacy')
C = unique(..., 'TreatMissingAsDistinct', tf)
[C, ia, ic] = unique(...)
| Parameter | Description |
|---|---|
| A | an nelson's variable (double, single, int8, int16, int32, int64, uint8, uint16, uint32, uint64, logical, char, string, cell). |
| tf | Missing values handling: true (default) each missing value (NaN, <missing>, <undefined>) is distinct, false repeated missing values are duplicates. |
| Parameter | Description |
|---|---|
| C | Unique data of A. |
| ia | Index to A: column vector. |
| ic | Index to C: column vector. |
C = unique(A) returns the unique elements of array A in sorted order.
C = unique(A, 'rows') considers each row of A as a unique entity and returns the unique rows in sorted order.
Note that the 'rows' option does not support cell arrays.
C = unique(A, 'stable') returns unique values in first-occurrence order.
C = unique(A, 'first') (default) or C = unique(A, 'last') selects, respectively, the first or the last occurrence of each repeated value for the index ia.
C = unique(A, 'legacy') preserves the behavior of unique from releases prior to R2013a. Values are returned in sorted order, ia points at the last occurrence of each repeated value, and, unless the 'rows' option is used, the index vectors ia and ic follow the orientation of a vector A (row vectors for a row-vector input). The 'legacy' flag cannot be combined with 'sorted', 'stable', 'first' or 'last'.
C = unique(..., 'TreatMissingAsDistinct', false) treats each repeated missing value as a duplicate: at most one missing value is included in C. By default (true), each missing value of A is included in C. With 'rows', rows are duplicates when they have missing values in the same columns and equal nonmissing values in the other columns. This option applies to numeric, string, categorical and table inputs and cannot be combined with 'legacy'.
[C, ia, ic] = unique(...) extends any of the previous syntaxes to also return index vectors ia and ic.
For a vector A, the relationships are C = A(ia) and A = C(ic).
For a matrix or array A, the relationships are C = A(ia) and A(:) = C(ic).
If the 'rows' option is used, the relationships are C = A(ia, :) and A = C(ic, :).
For a table A, each row is compared across all variables and C is a table: with 'sorted' (default) its rows are ordered as sortrows orders them, with 'stable' in first-occurrence order; C = A(ia, :) and A = C(ic, :). 'rows' is implied and 'legacy' is not supported.
A = [10+20i 30+i 10i 0 -10i];
[C, ia, ic] = unique(A)
A = {'hi', 'good'; 'good', 'tell'; 'hi', 'bye'}
[C, ia, ic] = unique(A)
A = [5 8 NaN NaN];
C1 = unique(A)
C2 = unique(A, 'TreatMissingAsDistinct', false)
| Version | Description |
|---|---|
| 1.6.0 | initial version |
| 2.0.0 | stable option added |
| 2.1.0 | 'first', 'last' and 'legacy' options added |
| 2.0.0 | 'TreatMissingAsDistinct' option added |