Effacer les filtres
Effacer les filtres

Counting number of zeros in column or row, without looping

19 vues (au cours des 30 derniers jours)
Ulrik Nash
Ulrik Nash le 8 Juil 2011
Hi Everyone,
If I have a matrix A, is there a way to create a 1,c vector containing the number of non-zeros in each columns, and simillarly, a r,1 vector containing the number of non-zeros in each row, all without looping?
Perhaps some use of nnz I am unaware of?
Regards,
Ulrik

Réponse acceptée

Nathan Greco
Nathan Greco le 8 Juil 2011
Given A:
idx = A~=0;
c = sum(idx,1);
r = sum(idx,2);

Plus de réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by