How to iterate until a point satisfies a certain condition?
Show older comments
Hi everyone! I need a suggestion for this code. I have this code:
x = [1,2,2,2,1;2,3,2,1,1];
y = [1,1,1,2,2;1,1,2,2,1];
plot(x,y,'-x')
xlim([0,3])
ylim([0,3])
axis equal

Applying this procedure, I obtain that the points that are unique such as (3;1) are removed. The code is this one:
%converts to points with x,y coordinates
points = [x(1,:),x(2,:);y(1,:),y(2,:)];
%initialize test array
repeat_arr = zeros(size(points,2),size(points,2));
for i_points = 1:size(points,2)
%find if a point is repeated excluding itself
repeat_arr(i_points,[1:i_points-1,i_points+1:end]) = all(points(:,i_points)==points(:,[1:i_points-1,i_points+1:end]),1) ;
end
% now we know for each points if it is repeated
temp = any(repeat_arr,1);
%Reverse the segment to point process so we can mask any segment that does not have a repeated point
edge_mask = all([temp(1:end/2); temp(end/2+1:end)]);
%Create X Y array of segment using out mask
x_edges = x(:,edge_mask);
y_edges = y(:,edge_mask);
plot(x_edges,y_edges,'-x')
xlim([0,3])
ylim([0,3])
axis equal

However, my question is: let us imagine that I have also a point of coordinates (2.5;1) like the one in the figure below, and that using this procedure I am able to remove the point (3;1). After this pruning, I would like the procedure to iterate until also the point (2.5;1) (that now is unique) is excluded and therefore execute as long as only the points in common to two or more segments remain. How can I do this in the most general way possible to be able to adapt it to other more complicated situations with more segments? I think that I need a while loop but, how can I set the condition?

Accepted Answer
More Answers (1)
the cyclist
on 21 Jun 2022
0 votes
(I didn't fully understand the condition, so I can't be more specific than that.)
Categories
Find more on Process Point Clouds 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!



