In Matlab, there is this unique command that returns thew unique rows in an array. This is a very handy command.
But the problem is that I can\'t assign tolerance to
As of R2015a, there is finally a function to do this, uniquetol (before R2015a, see my other answer):
uniquetol
Set unique within a tolerance.
uniquetol
is similar tounique
. Whereasunique
performs exact comparisons,uniquetol
performs comparisons using a tolerance.
The syntax is straightforward:
C = uniquetol(A,TOL)
returns the unique values inA
using toleranceTOL
.
As are the semantics:
Each value of
C
is within tolerance of one value ofA
, but no two elements inC
are within tolerance of each other.C
is sorted in ascending order. Two valuesu
andv
are within tolerance if:
abs(u-v) <= TOL*max(A(:),[],1)
It can also operate "ByRows
", and the tolerance can be scaled by an input "DataScale
" rather than by the maximum value in the input data.
But there is an important note about uniqueness of the solutions:
There can be multiple valid
C
outputs that satisfy the condition, "no two elements inC
are within tolerance of each other." For example, swapping columns inA
can result in a different solution being returned, because the input is sorted lexicographically by the columns. Another result is thatuniquetol(-A,TOL)
may not give the same results as-uniquetol(A,TOL)
.
There is also a new function ismembertol
is related to ismember
in the same way as above.