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]

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 3 Mai 2017

0 votes

out = sum(A(:))

3 commentaires

Thank you so much! worked like a charm
and one more, if I want the average of it, so i just change 'sum' to 'mean' is it?
Andrei Bobrov
Andrei Bobrov le 3 Mai 2017
yes

Connectez-vous pour commenter.

Plus de réponses (2)

KL
KL le 3 Mai 2017
Modifié(e) : KL le 3 Mai 2017

0 votes

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)

Catégories

En savoir plus sur Sparse Matrices dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by