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

2 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by