Need to determine the fraction of a matrix of ones and zeroes that are zeroes

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Nov. de 2016
mean(Y(:)) * 100

Más respuestas (1)

Steven Lord
Steven Lord el 14 de Nov. de 2016
Get the number of nonzeros using nnz and the total number of elements using numel.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by