Hi,
Why MATLAB is not executing the body of the following selection if statement eventhough I believe the condition is true? Your help would be appreciated!
Note: members is a 1by 3 cell. attack = 5, n1=7
for ii=1:n1 % Check if neighboring nodes will survive the cascading failure or not
if ~ismember(ii,members{1}) && ~ii==attack
A(ii,:)=0;
A(:,ii)=0;
C(ii,:)=0; % All nodes in Layer B coupled to neighboring nodes will get failed
C(:,ii)=0;
end
end

3 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 10 月 12 日
Unfortunately, believing is not enough. Add breakpoint at the line of if statement and check why the condition remains false. https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html
Waseem AL Aqqad
Waseem AL Aqqad 2020 年 10 月 12 日
This is what I did actually before posting this question
Waseem AL Aqqad
Waseem AL Aqqad 2020 年 10 月 12 日
But thanks for sharing that useful page.

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2020 年 10 月 12 日
編集済み: Stephen23 2020 年 10 月 12 日

1 投票

Solution: the logic is incorrect:
~ii==attack
should be
ii~=attack
Explanation: the code
~ii==attack
following the rules of operator precedence is equivalant to
(~ii)==attack
which for the case that both ii and attack are non-zero is equivalent to
false==true
which is thus simply equivalent to
false

2 件のコメント

Waseem AL Aqqad
Waseem AL Aqqad 2020 年 10 月 12 日
Thank you very much, Stephen!
Waseem AL Aqqad
Waseem AL Aqqad 2020 年 10 月 12 日
Thanks for the explanation.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2020 年 10 月 12 日

編集済み:

2020 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by