Find rows containing N zeros in a matrix
2 次查看(过去 30 天)
显示 更早的评论
I have a matrix like:
mat =[1 2 3;
0 0 3;
1 2 0;
0 0 0;
2 0 0];
To find a row full of zeros I do:
mat(all(mat==0,2)
ans =
0 0 0
What can I do to find the rows which only two zeros?
To get this:
ans =
0 0 3
2 0 0
0 个评论
采纳的回答
Azzi Abdelmalek
2014-1-16
编辑:Azzi Abdelmalek
2014-1-17
mat(sum(mat==0,2)==2,:)
For general case
N=2
out=mat(sum(mat==0,2)==N,:)
3 个评论
更多回答(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!