unique
Returns the unique elements in the input x
Syntax
unique(x)
unique(x,'rows')
unique(x,'first')
unique(x,'last')
[R,idx,idy] = unique(...)
Inputs
- x
- Any valid scalar | vector | matrix.
- rows
- Specifies to search for common rows as opposed to common elements.
- last
- Default option. Returns the highest possible indices in x.
- first
- Default option. Returns the lowest possible indices in x.
Outputs
- R
- The unique elements in input x.
- idx
- The idx vector relates the values in Y to the corresponding index in x such that x(idx)=R
- idy
- The idy vector relates the values in x to the corresponding index in Y such that R(idy)=x
Examples
unique([1;4;6;3;3;6;1;1])
R = [ 1 ; 3 ; 4 ; 6 ]
[R,idx,idy]=unique([1;4;6;3;3;6;1;1], 'rows')
R = [ 1 ; 3 ; 4 ; 6 ]
idx = [ 8 ; 5 ; 2 ; 6 ]
idy = [ 1 ; 3 ; 4 ; 2 ; 2 ; 4 ; 1 ; 1 ]
[R,idx,idy]=unique([1;4;6;3;3;6;1;1],'first')
R = [ 1 ; 3 ; 4 ; 6 ]
idx = [ 1 ; 4 ; 2 ; 3 ]
idy = [ 1 ; 3 ; 4 ; 2 ; 2 ; 4 ; 1 ; 1 ]