What condition to use for checking whether at least a single negative element in a array?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Neil Sam
am 10 Apr. 2018
Kommentiert: Neil Sam
am 10 Apr. 2018
For example, what condition to use instead of '<' to execute the content inside if (to check if whether at least a single negative entry exists)?
A=[1;-1];
B=[3;4];
if (A.*B < 0)
disp (A.*B)
end
0 Kommentare
Akzeptierte Antwort
Roger Stafford
am 10 Apr. 2018
Bearbeitet: Roger Stafford
am 10 Apr. 2018
Use the 'any' logical function.
if any(A.*B<0)
If you are dealing with an array, C, of more than one dimension, do this:
if any(C(:)<0)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!