How to check number of zeros in an array?
118 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Aswin Sandirakumaran
le 6 Juil 2018
Réponse apportée : Raul Andres Lopez Romero
le 6 Juil 2018
Eg: I have a vector A = [0,0,4,3] and B = [0,1,2,3,4] and C = [0,0,0,0,0] and D = [0,1,2,0,0]
SO THE OUTPUT SHOULD CONTAIN NUMBER OF ZEROS IN EACH VECTOR:
A = 2
B = 1
C = 5
D = 3
0 commentaires
Réponse acceptée
Plus de réponses (1)
Raul Andres Lopez Romero
le 6 Juil 2018
Try this:
nzeros=numel(A)-nnz(A)
numel(X) give you the number of elements in an array, nnz(X) give you the numbers of Non zero elements in an array.
try it for every array you have.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!