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.

采纳的回答

Walter Roberson
Walter Roberson 2016-11-13
mean(Y(:)) * 100

更多回答(1 个)

Steven Lord
Steven Lord 2016-11-14
Get the number of nonzeros using nnz and the total number of elements using numel.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by