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

조회 수: 41 (최근 30일)
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

채택된 답변

Roger Stafford
Roger Stafford 2018년 4월 10일
편집: Roger Stafford 2018년 4월 10일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by