Executing the body of IF statement.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Waseem AL Aqqad
le 12 Oct 2020
Modifié(e) : Stephen23
le 12 Oct 2020
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/377821/image.jpeg)
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 commentaires
Réponse acceptée
Stephen23
le 12 Oct 2020
Modifié(e) : Stephen23
le 12 Oct 2020
Solution: the logic is incorrect:
~ii==attack
should be
ii~=attack
Explanation: the code
~ii==attack
(~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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!