MATLAB: How to get the total count of non zero&non NaN elements by column

data acquisitionData Acquisition ToolboxstatisticsStatistics and Machine Learning Toolbox

Hi,
I have below Matrix, and I want to get the total count of "non zeor & non nan" elements in each column.
My Input:
1 0 nan 0 nan
2 0 1 0 nan
4 6 3 0 nan
I want the below output;
Output:
3 1 2 0 0
Kindly some one help

Best Answer

a =[1 0 nan 0 nan
2 0 1 0 nan
4 6 3 0 nan]
out = sum(~isnan(a) & a ~= 0);