Hi, is it possible to count the number of ones in a matrix ?
조회 수: 357 (최근 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!