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
Ais a table or timetable, thenuniquereturns the unique rows inAin sorted order. For timetables,uniquetakes row times and row values into account when determining whether rows are unique, and sorts the output timetableCby row times.If
Ais a categorical array, then the sort order is determined by the order of the categories.
specifies whether to return the first or last indices of repeated values for
either of the previous syntaxes.C = unique(___,occurrence)
preserves the behavior of the C = unique(___,"legacy")unique function from R2012b
and previous releases. Specifying the "legacy" option with
TreatMissingAsDistinct or with both the
setOrder and occurrence arguments is
not supported. The "legacy" option does not support
categorical arrays, datetime arrays,
duration arrays, calendarDuration arrays,
tables, or timetables.
[
also returns index vectors C,ia,ic] = unique(___)ia and ic
using any of the previous syntaxes.
If
Ais a vector, thenC = A(ia)andA = C(ic).If
Ais a matrix or array, thenC = A(ia)andA(:) = C(ic).If you specify the
"rows"option, thenC = A(ia,:)andA = C(ic,:).If
Ais a table or timetable, thenC = A(ia,:)andA = C(ic,:).
Examples
Input Arguments
Output Arguments
Tips
Use
uniquetolto 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 variable subscripting. For example, you can use
unique(A(:,, wherevars))varsis a positive integer, a vector of positive integers, a variable name, a cell array of variable names, or a logical vector. Alternatively, you can usevartypeto create a subscript that selects variables of a specified type.