Exclude some nodes from a 3D point cloud (select only neighboring nodes)

Hi! I would need code to create a matrix of nodes excluding those circled in red. Is there any code that I could use?
I would need a code where, for example, I select a node I am interested in and it automatically selects all neighboring nodes (within a certain distance x,y,z).
selection = importdata("selection.mat");
figure
plot3(selection(:,1),selection(:,2),selection(:,3),'b.','Markersize',5)
grid on
hold on
axis equal
xlabel('x')
ylabel('y')
zlabel('z')

 Accepted Answer

X=load('selection').selection; %shorten data name
G=graph(pdist2(X,X)<=10);
T=conncomp(G);
[~,i]=max(histcounts(T,[unique(T),inf]));
I=T==i;
plot3(X(I,1),X(I,2),X(I,3),'b.','Markersize',5); hold on
plot3(X(~I,1),X(~I,2),X(~I,3),'r.','Markersize',5); hold off
grid on
axis equal
xlabel('x'),ylabel('y'),zlabel('z')

More Answers (0)

Products

Release

R2021b

Asked:

on 11 May 2023

Edited:

on 13 May 2023

Community Treasure Hunt

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

Start Hunting!