Question: In Matlab, there is this [`unique` command](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/unique.html) 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 it-- in double precision, we always have to compare two elements within a precision. Is there a built-in command that returns unique elements, within a certain tolerance?

Answer: 
**As of R2015a**, there is finally a function to do this, [`uniquetol`](http://www.mathworks.com/help/matlab/ref/uniquetol.html) (**before R2015a**, see [my other answer](https://stackoverflow.com/a/20850949/2778484)):

> 
> `uniquetol` Set unique within a tolerance.  
>   
> 
>      `uniquetol` is similar to `unique`. Whereas `unique` performs exact comparisons, `uniquetol` performs comparisons using a tolerance.
> 
> 
> 

The syntax is straightforward:

> 
> `C = uniquetol(A,TOL)` returns the unique values in `A` using tolerance `TOL`.
> 
> 
> 

As are the semantics:

> 
> Each value of `C` is within tolerance of one value of `A`, but no two elements in `C` are within tolerance of each other. `C` is sorted in ascending order. Two values `u` and `v` 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 in `C` are within tolerance of each other." For example, swapping columns in `A` can result in a different solution being returned, because the input is sorted lexicographically by the columns. Another result is that `uniquetol(-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.
I was stuck the other day with a **MatLab 2010**, so, no round(X,n), no \_mergesimpts (At least I couldn't get it to work) so, a simple solution that works (at least for my data): 

Using `rat` default tolerance:

```
unique(cellstr(rat(x)))

```

Other tolerance:

```
unique(cellstr(rat(x,tol)))

```