determine all cells are non-zero within a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Peng Zhao
am 3 Jul. 2019
Kommentiert: Peng Zhao
am 3 Jul. 2019
I am trying to determine if all of the numbers in "x" is non-zero values:
x = [1 1 0]
% 1:
if x ~= [0 0 0]
disp('x is not zeros')
end
% 2:
if all(x ~= 0)
disp('x is not zeros')
end
but the output is saying the x is zeros.
what mistake did I make?
4 Kommentare
Adam
am 3 Jul. 2019
And why isn't this the expected answer? You are testing if all elements of Pref_Color are not equal to 0. Clearly this is false because the final element is 0 therefore it drops into your else block and reports 'no'.
Akzeptierte Antwort
Matt J
am 3 Jul. 2019
Your second if statement is correct, and I get the correct output (none).
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!