unique
Returns the elements of a set, without duplication.
Syntax
unique(x)
unique(x,'first')
unique(x,'last')
unique(x,'sorted')
unique(x,'stable')
unique(x,'rows')
[y,idx,idy] = unique(...)
Inputs
- x
- The set from which to remove duplicate items.
- 'last' (Default)
- Returns idx with the highest indices for the items in x,
- 'first'
- Returns idx with the lowest indices for the items in x,
- 'sorted'
- Returns unique elements in ascending order, with 'last' implied for the idx output.
- 'stable'
- Returns unique elements in their original order, with 'first' implied for the idx output.
- 'rows'
- Returns unique rows as opposed to unique elements.
Outputs
- y
- The unique elements of x.
- idx
- The vector of indices such that x(idx) = y.
- idy
- The vector of indices such that such that y(idy) = x.
Examples
y = unique([1,4,6,3,3,6,1,1])
y = [Matrix] 1 x 4
1 3 4 6
[y,idx,idy] = unique([1,4,6,3,3,6,1,1],'first')
= [Matrix] 1 x 4
1 3 4 6
idx = [Matrix] 1 x 4
1 4 2 3
idy = [Matrix] 1 x 8
1 3 4 2 2 4 1 1
[y,idx,idy] = unique([1,4,6;3,3,6;8,6,9;3,3,6], 'rows')
y = [Matrix] 3 x 3
1 4 6
3 3 6
8 6 9
idx = [Matrix] 3 x 1
1
4
3
idy = [Matrix] 4 x 1
1
2
3
2