Extracting some points and finding some nearest elements.

1 次查看(过去 30 天)
I have data I used dbscan clustering method. Now I need to find 5 different elements from each cluster. And calculate the 5 nearest elements of each point and group it.
In the below figure there are some points marked(pencil marked)and grouped the 5 elements(black round).
[I marked only 3 clusters just for example, I need it in the full clusters.]
After that how can I remove those clusters that do not have 5 nearest elements? Anybody, please help me.
clc;
clear;
data=xlsread('glass.xlsx');
minpts=6;
epsilon=4;
[idx, corepts] = dbscan(data,epsilon,minpts);
gscatter(data(:,1),data(:,2),idx);

回答(1 个)

Image Analyst
Image Analyst 2020-3-8
I don't even think you need dbscan for this. You just need to define a length that separates "near enough" and "too far away". Then you just check every point in the array to see if it has 5 that are near enough, and keep those.
nearEnough = 0.02; % Whatever you want.
x = data(:,1);
y = data(:,2);
indexesToKeep = false(1, length(x)); % Initialize to not keeping any of them.
for k = 1 : length(x)
distances = sqrt((x(k) - x).^2 + (y(k) - y).^2);
if sum(distances > nearEnough) >= 5
% At least 5 are close enough to this k'th point, so keep this point.
indexesToKeep(k) = true;
end
end
x = x(indexesToKeep);
y = y(indexesToKeep);
  12 个评论
sreelekshmi ms
sreelekshmi ms 2020-3-10
At-least In the glass data set how can I apply the above steps I described. Please help me.
sreelekshmi ms
sreelekshmi ms 2020-3-11
Is there any way to divide the data based on dense areas. If any, please help me.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by