matlab计算矩阵每列非0元素个数

在统计分析中,有时候需要计算矩阵每列非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

原文地址:https://www.cnblogs.com/startover/p/3369573.html