counting the number of non-zero or zero elements in a specific direction of an array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mnr
le 3 Mai 2015
Réponse apportée : Star Strider
le 3 Mai 2015
Hello there,
I have an 8x3x5 array, and would like to count its number of zeros and non-zeros across its 3rd dimension. In particular, I would like to get a 1x5 vectors that gives me the number of zero elements, and another 1x5 vectors showing the number of ones. I would appreciate if somebody can help me. Thanks.
0 commentaires
Réponse acceptée
Star Strider
le 3 Mai 2015
This seems to work:
NZ = sum(squeeze(sum(M==0,1))); % Zero Elements
NNz = sum(squeeze(sum(M~=0,1))); % Non-Zero Elements
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!