delete points too close to another
Show older comments
Hello! I need to delete in a matrix that contain a number of points described from 3 numbers that refer to coordinates. I pick from this matrix a random point and than i want to delete all the points in the matrix too close (closer then s*r+delta)from the one I picked and than repeate this procedure N_part times. I use this code but points too close remain in matrix. pos is the matrix Nx3
pos=[
2 4 5
3 54 7
3 87 64
];
for i=1:N_part
x_coord(i)=pos(randi([1,dimension],1),1);
y_coord(i)=pos(randi([1,dimension],1),2);
z_coord(i)=pos(randi([1,dimension],1),3);
%
index=find((sqrt(pos(:,1)-x_coord(i)).^2+(pos(:,2)-y_coord(i)).^2+(pos(:,3)-z_coord(i)).^2)< 2*r+delta );
pos(index,:)=[];
dimension=size(pos,1);
end
Answers (1)
John D'Errico
on 15 Dec 2016
0 votes
This is not always a trivial problem to solve, and it gets worse in multiple dimensions. One option is to use my consolidator . Download it from the file exchange. It was deigned to handle the 1-dimensional data, but the same idea also works on n-dimensional data, so I extended it to work there too.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!