Hi, is it possible to count the number of ones in a matrix ?
242 ビュー (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!