I have a 241 x 340 matrix that contains only 1 and 0 value scattered over the matrix. My question is how can I calculate the sum value of 1 in the matrix? Thank You in advance. for example
A = [0 0 0 0 1 1 1 1 0 0 1 1 1 0; 1 1 1 0 0 1 1 1 0 0 0 1 1 0]

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 5월 3일

0 개 추천

out = sum(A(:))

댓글 수: 3

Thank you so much! worked like a charm
and one more, if I want the average of it, so i just change 'sum' to 'mean' is it?
Andrei Bobrov
Andrei Bobrov 2017년 5월 3일
yes

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KL
KL 2017년 5월 3일
편집: KL 2017년 5월 3일

0 개 추천

See Image Analyst's answer here
A = [0 0 0 0 1 1 1 1 0 0 1 1 1 0; 1 1 1 0 0 1 1 1 0 0 0 1 1 0]
edges = unique(A)
counts = histc(A(:), edges)

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by