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.
0 件のコメント
回答 (1 件)
Walter Roberson
2022 年 7 月 12 日
I already showed you a suitable while loop in https://www.mathworks.com/matlabcentral/answers/1745230-how-to-iterate-until-a-point-satisfies-a-certain-condition#comment_2241080
1 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!