MATLAB Answers

What condition to use for checking whether at least a single negative element in a array?

조회 수: 1(최근 30일)
Neil Sam
Neil Sam 10 Apr 2018
Commented: Neil Sam 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

로그인 to comment.

채택된 답변

Roger Stafford
Roger Stafford 10 Apr 2018
Roger Stafford 님이 편집함. 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)

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by