Sum of certain value in a matrix

1 Ansicht (letzte 30 Tage)
EMIRA SYAMIMI AHMAD SUBRI
Kommentiert: Andrei Bobrov am 3 Mai 2017
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]

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 3 Mai 2017
out = sum(A(:))
  3 Kommentare
EMIRA SYAMIMI AHMAD SUBRI
and one more, if I want the average of it, so i just change 'sum' to 'mean' is it?
Andrei Bobrov
Andrei Bobrov am 3 Mai 2017
yes

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

KL
KL am 3 Mai 2017
Bearbeitet: KL am 3 Mai 2017
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 am 3 Mai 2017

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by