Counting number of zeros in column or row, without looping

9 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by