Number of non-zero element

3 visualizaciones (últimos 30 días)
Hg
Hg el 16 de Mzo. de 2016
Comentada: Hg el 16 de Mzo. de 2016
I have n-number of arrays, I want to find the total non-zero element at a location. For example there are three arrays as following:
A = [2 0 0 2;
0 1 1 1;
1 3 0 0;
0 1 0 1];
B = [0 2 1 0;
3 1 1 1;
2 0 0 2;
0 1 0 1];
C = [0 2 3 0;
3 1 2 2;
4 0 2 1;
2 0 0 1]
How can I find the total number of non-zero elements in A, B, C for each location, e.g (1,1): 1, (1,2): 2, (1,3): 2 ? To get array D = [1 2 2 1; 2 3 3 3; ... ].

Respuesta aceptada

James Tursa
James Tursa el 16 de Mzo. de 2016
Editada: James Tursa el 16 de Mzo. de 2016
D = sum(cat(3,A,B,C)~=0,3);
  1 comentario
Hg
Hg el 16 de Mzo. de 2016
Never thought about that! Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by