Hi, is it possible to count the number of ones in a matrix ?
297 次查看(过去 30 天)
显示 更早的评论
Example: Suppose we a have a matrix A=[1 0 0 1 0 0; 1 0 0 0 1 1]; how do I count the number of ones in this matrix??
0 个评论
采纳的回答
Ahmet Cecen
2016-4-8
编辑:Ahmet Cecen
2016-4-8
sum(A(:) == 1);
6 个评论
Walter Roberson
2021-6-21
A = randi([0 1], 5, 5); A = xor(A,A.'); %random symmetric
A
[r,c] = find(A);
mask = r>=c;
r = r(mask); c = c(mask);
[r,c]
or
[r,c] = find(tril(A))
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!