Sum of certain value in a matrix

1 visualizzazione (ultimi 30 giorni)
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]

Risposta accettata

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

Accedi per commentare.

Più risposte (2)

KL
KL il 3 Mag 2017
Modificato: KL il 3 Mag 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 il 3 Mag 2017

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by