How to avoid an Infinite Loop?
6 ビュー (過去 30 日間)
I'm encountering an infinite loop problem. I tried to debug my code but couldn't figure it out, so I would appreciate your thoughts and ideas.
[nComponents,sizes,members] = networkComponents(NetA);
[nComponentsB,sizesB,membersB] = networkComponents(NetB);
if nnz(NetA(ii,:))<1 && nnz(NetA(:,ii))<1 && ~ismember(ii,attack)
C(ii,:)=0; % All nodes in Layer B coupled to neighboring nodes will get failed
% Propagation back to Layer A
if nnz(NetB(pp,:))<1 && nnz(NetB(:,pp))<1
"NetA" and "NetB" are square symmetric matrices.
"inda" and "indb" are row vectors of the same size.
"attack" and "Nodes" are positive integers.
"sizes(1)" and "sizesB(1)" are positive integers.
回答 (1 件)
David Goodmanson 2020 年 11 月 7 日
編集済み: David Goodmanson 2020 年 11 月 7 日
Nothing in the entire while loop alters either 'sizes' or 'sizesB'. So if sizes(1) ~= sizesB(1), that condition will not ever change, leading to an infinite while loop. For the loop to terminate, you will have to change either sizes(1) or sizesB(1) within the loop, in such a way that the two eventually are equal.