在统计分析中,有时候需要计算矩阵每列非0元素的个数,可以用以下方法:

先用find找到每列不为0的元素index,然后用count计数。

假设有矩阵A[M,N], 结果存在countZeros

countZeros=zeros(1,N);

for i=1:M

     countZeros(i)=length(find(A(:,i)>0);

end

相关文章:

  • 2021-10-18
  • 2021-06-14
  • 2021-08-21
  • 2021-11-10
  • 2021-11-19
  • 2022-01-02
  • 2021-08-25
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-01-13
  • 2022-01-01
  • 2021-09-30
  • 2021-12-01
相关资源
相似解决方案