Sum of certain value in a matrix

조회 수: 1 (최근 30일)
EMIRA SYAMIMI AHMAD SUBRI
EMIRA SYAMIMI AHMAD SUBRI 2017년 5월 3일
댓글: Andrei Bobrov 2017년 5월 3일
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일
out = sum(A(:))
  댓글 수: 3
EMIRA SYAMIMI AHMAD SUBRI
EMIRA SYAMIMI AHMAD SUBRI 2017년 5월 3일
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일
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)

Aniruddha Katre
Aniruddha Katre 2017년 5월 3일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by