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):
uniquetolSet unique within a tolerance.
uniquetolis similar tounique. Whereasuniqueperforms exact comparisons,uniquetolperforms comparisons using a tolerance.
The syntax is straightforward:
C = uniquetol(A,TOL)returns the unique values inAusing toleranceTOL.
As are the semantics:
Each value of
Cis within tolerance of one value ofA, but no two elements inCare within tolerance of each other.Cis sorted in ascending order. Two valuesuandvare 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
Coutputs that satisfy the condition, "no two elements inCare within tolerance of each other." For example, swapping columns inAcan 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.