How to find the sum of each element of a matrix?

조회 수: 2 (최근 30일)
peyush
peyush 2015년 6월 28일
댓글: peyush 2015년 6월 28일
I have a binary image with some pixel values 1 and rest 0...I want to find out the sum of all the pixel values in the image...can any one help?

채택된 답변

dpb
dpb 2015년 6월 28일
If x is the array,
xsum=sum(x(:)); % ":" is a Matlab idiom that returns all elements in a column vector
  댓글 수: 3
Image Analyst
Image Analyst 2015년 6월 28일
That will work regardless of how many dimensions x has. By the way, a matrix is an array.
peyush
peyush 2015년 6월 28일
thanks both of you :-)

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by