I want to compare three logics should I used && or || or any other way to do that ?????
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
shane watson
am 20 Feb. 2017
Kommentiert: shane watson
am 23 Feb. 2017
I want to compare three logics should I used && or or any other way to do that ?????
5 Kommentare
Adam
am 23 Feb. 2017
Tags are meant to give useful keywords related to the problem so people with the right expertise can find them quickly.
Akzeptierte Antwort
Jan
am 20 Feb. 2017
Bearbeitet: Jan
am 20 Feb. 2017
The | operator acts like or(), while || requires scalar arguments:
a = 1
b = 0
A = false(1, 4);
B = true(1, 4);
or(a, b) % correct
a | b % correct, but this is faster:
a || b % correct and efficient
A || B % fail
or(A, B) % correct
A | B % correct
The same for &&. The || and && operator apply a short-curcuiting: If the first operand determines the output alread like in 0&&1, the second is not evaluated. This matters, if the operands are functions:
str = 'asd';
if length(str > 3) && str(4) == 'f' % Handles 'asd' correctly!
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!