How do I insert a working code inside a while loop procedure?

1 view (last 30 days)
Hi everyone! I have the following problem.
I have built a code (which works) whose aim is to eliminate those points in the segments that are present only once, in order that only points common to two or more segments remain. The problem is that my procedure works only for one iteration. Instead, I would like to insert my procedure in something like a while loop in order to repeat this pruning until only points common to two or more segments remain.
I give you an example simpler with respect to my case:
let us imagine that we have also a point of coordinates (2.5;1) and that using my procedure we are able to eliminate the point (3;1) and so to prune the segment between (2.5;1) and (3;1). I would like the procedure to iterate until this second segment joining (2.5;1) with (2;1) is also excluded and therefore only the points in common to two or more segments remain.
However I have not idea how to set this iterative loop. Could anyone help me? Thanks in advance.

Answers (1)

Walter Roberson
Walter Roberson on 12 Jul 2022
  1 Comment
Walter Roberson
Walter Roberson on 13 Jul 2022
I already showed you a suitable while loop in the post I indicated.
In outline form:
make the initial graph the current graph
while true
attempt to find things to remove from your current graph
if the list of things to delete is empty
break;
end
remove the found things from your current graph, producing a new current graph
end
The above does not modify the initial graph, so you can now do things like compare the original graph and the current graph.
The above does not depend upon the representation of the graph.
You can easily modify the above sequence to
attempt to find one thing to remove from your current graph
though that does introduce questions about what order to remove things in when there are multiple choices.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!