필터 지우기
필터 지우기

Counting number of zeros in column or row, without looping

조회 수: 19 (최근 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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by