How to group points with given tolerance in Matlab

Viewed 83

There's set of points in 2D plane.

points = [2, 2; 
          10, 12; 
          1, 1; 
          3,3; 
          5, 10]

Some points are in close proximity to others and form clusters/clouds. How to replace such cluster with one point given that cluster can be on area specified by some treshold t?

output = [2, 2; 
          10, 12;  
          5, 10]

In more graphic way:

example input and output

Are there any algorithms/solutions that would be a good choice here?

1 Answers

You can use uniquetol:

output = uniquetol(points, tol, 'ByRows', true, 'DataScale', 1);

Note that uniquetol uses absolute difference instead of squared difference.

Related