What condition to use for checking whether at least a single negative element in a array?
22 ビュー (過去 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
0 件のコメント
採用された回答
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!