unique
Unique values
Syntax
Description
returns the same data as in C
= unique(A
)A
, but with no repetitions.
C
is in sorted order.
If
A
is a table or timetable, thenunique
returns the unique rows inA
in sorted order. For timetables,unique
takes row times and row values into account when determining whether rows are unique, and sorts the output timetableC
by row times.If
A
is a categorical array, then the sort order is determined by the order of the categories.
specifies which indices to return in case of repeated values.
C
= unique(A
,occurrence
)occurrence
can be 'first'
(default) or
'last'
.
[
also returns index vectors C
,ia
,ic
] = unique(___)ia
and ic
using any of the previous syntaxes.
If
A
is a vector, thenC = A(ia)
andA = C(ic)
.If
A
is a matrix or array, thenC = A(ia)
andA(:) = C(ic)
.If the
'rows'
option is specified, thenC = A(ia,:)
andA = C(ic,:)
.If
A
is a table or a timetable, thenC = A(ia,:)
andA = C(ic,:)
.
[
,
C
,ia
,ic
]
= unique(A
,'legacy')[
,
C
,ia
,ic
]
= unique(A
,'rows','legacy')[
,and
C
,ia
,ic
]
= unique(A
,occurrence
,'legacy')[
preserve the behavior of the C
,ia
,ic
]
= unique(A
,'rows',occurrence
,'legacy')unique
function from R2012b
and prior releases.
The 'legacy'
option does not support categorical arrays,
datetime arrays, duration arrays, calendarDuration arrays, tables, or
timetables.
Examples
Input Arguments
Output Arguments
Tips
Use
uniquetol
to find unique floating-point numbers using a tolerance.To find unique rows in tables or timetables with respect to a subset of variables, you can use column subscripting. For example, you can use
unique(A(:,
, wherevars
))vars
is a positive integer, a vector of positive integers, a variable name, a cell array of variable names, or a logical vector. Alternatively, you can usevartype
to create a subscript that selects variables of a specified type.
Extended Capabilities
Version History
Introduced before R2006a