Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Unique values in array

`C = unique(A)`

`C = unique(A,'rows')`

```
[C,ia,ic]
= unique(A)
```

```
[C,ia,ic]
= unique(A,'rows')
```

```
[C,ia,ic]
= unique(A,setOrder)
```

```
[C,ia,ic]
= unique(A,'rows',setOrder)
```

```
[C,ia,ic]
= unique(A,'legacy')
```

```
[C,ia,ic]
= unique(A,'rows','legacy')
```

```
[C,ia,ic]
= unique(A,occurrence,'legacy')
```

```
[C,ia,ic]
= unique(A,'rows',occurrence,'legacy')
```

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, then`unique`

returns the unique rows in`A`

in sorted order. For timetables,`unique`

takes row times and row values into account when determining whether rows are unique, and sorts the output timetable`C`

by row times.

`[`

, `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, tables, or timetables.

To find unique rows in table or timetable

`A`

with respect to a subset of variables, you can use column subscripting. For example, you can use`unique(A(:,`

, where))`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 use`vars`

`vartype`

to create a subscript that selects variables of a specified type.

Was this topic helpful?