use of short Circuit operator
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, How can I use short circuit operators(&&) in vector variable?
0 commentaires
Réponse acceptée
Walter Roberson
le 15 Oct 2012
You cannot. && can only be used for scalars.
Note that if you are trying to code something like
if vector1 && vector2
then the "if" would be considered true only if all values in "vector1 && vector2" evaluated to true, because that is how "if" behaves on vectors and matrices, as if there was an all() wrapped around everything:
if all(vector1 && vector2)
With some minor thought on the meaning of "&" you can see this would be the same as
if all(all(vector1) && all(vector2))
which could be written more briefly as
if all(vector1) && all(vector2)
which is allowed.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Visualization and Data Export 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!