delete points too close to another
显示 更早的评论
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
回答(1 个)
John D'Errico
2016-12-15
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!