What condition to use for checking whether at least a single negative element in a array?
18 次查看(过去 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!