How to get the total count of non zero&non NaN elements by column
17 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Andrei Bobrov
2016-10-7
编辑:Andrei Bobrov
2016-10-7
a =[1 0 nan 0 nan
2 0 1 0 nan
4 6 3 0 nan]
out = sum(~isnan(a) & a ~= 0);
2 个评论
Andrei Bobrov
2016-10-7
a = {1 0 nan 0 nan
2 0 1 0 nan
4 6 3 0 nan};
out = sum(cellfun(@(a)~isnan(a) & a ~= 0,a));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!