필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Loren99
Loren99 2022년 7월 12일
편집: Loren99 2022년 9월 15일
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에서 Directed Graphs에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by