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

1 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2022-7-12
  1 个评论
Walter Roberson
Walter Roberson 2022-7-13
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by