Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
peyush
peyush am 28 Jun. 2015
Kommentiert: peyush am 28 Jun. 2015
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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by