what will be displayd and why?
Ältere Kommentare anzeigen
-------------------------------------
if (x)
disp('true');
else
disp('false');
end;
if (~x)
disp('true');
else
disp('false');
end;
----------------------------------------
For the case x=[0 0 0 0]
and for the case x=[0 1 0 1]
1 Kommentar
Akzeptierte Antwort
Weitere Antworten (2)
David Shapiro
am 13 Mär. 2015
0 Stimmen
Image Analyst
am 13 Mär. 2015
0 Stimmen
The all zero case is obvious. x=[0 0 0 0] is false no matter how you look at it - no way it can be true.
But if you have a case like [1 2 0 1] or [0 1 0 1] or [1,2,3,4], it will be true only if ALL of the elements are non-zero.
2 Kommentare
David Shapiro
am 13 Mär. 2015
Adam
am 13 Mär. 2015
In this case (a vector) it seems to be shorthand for
if ( all(x) )
though I never tend to use that shorthand myself as I prefer the explicit use of all or any when using logicals for an if statement.
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!