Need to determine the fraction of a matrix of ones and zeroes that are zeroes
1 次查看(过去 30 天)
显示 更早的评论
I need to determine the fraction of a matrix of ones and zeroes that are zeroes.
My code is:
function y = zero_stat(Y)
K=mean(Y');
[x,y] = size(Y');
r = mean(Y',y);
s = sum(r);
y=(1-s)/y)*100;
end
IF 40% of the matrix is comprised of zeroes, the function is to return 40.
0 个评论
采纳的回答
更多回答(1 个)
Steven Lord
2016-11-14
Get the number of nonzeros using nnz and the total number of elements using numel.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!