Sum of certain value in a matrix

1 visualización (últimos 30 días)
EMIRA SYAMIMI AHMAD SUBRI
EMIRA SYAMIMI AHMAD SUBRI el 3 de Mayo de 2017
Comentada: Andrei Bobrov el 3 de Mayo de 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]

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (2)

KL
KL el 3 de Mayo de 2017
Editada: KL el 3 de Mayo de 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 el 3 de Mayo de 2017

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by