フィルターのクリア

Counting number of zeros in column or row, without looping

20 ビュー (過去 30 日間)
Ulrik Nash
Ulrik Nash 2011 年 7 月 8 日
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);
  1 件のコメント
Ulrik Nash
Ulrik Nash 2011 年 7 月 8 日
Thank you Nathan, much appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by