Clusterig points in clusters, separated by a minimum distance
2 次查看(过去 30 天)
显示 更早的评论
I have a set of 300 points, defined by x and y coordinates in separat vectors. I want to cluster the points in such a way, that every center of the cluster is at least a defined distance from the closest other one. The distance can not be less than the defined one.
Is there a way that I dont have to define the exact number of clusters?
Which function should I use?
Thanks in advance for the response
0 个评论
回答(1 个)
Akshat
2024-9-4
Hi Alexamder,
The functionality you are asking for, which involves clustering points with a threshold for a neighborhood search radius, is provided in MATLAB using "dbscan".
Here is the documentation for the same:
I have written a sample code with 300 points for you to see how the function works, here:
x = rand(300, 1) * 100;
y = rand(300, 1) * 100;
data = [x, y];
epsilon = 5; % Minimum distance between cluster centers
min_samples = 5; % Minimum number of points to form a cluster
idx = dbscan(data, epsilon, min_samples);
figure;
gscatter(data(:,1), data(:,2), idx);
xlabel('X');
ylabel('Y');
grid on;
Hope this helps with your problem statement!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!