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

1 回表示 (過去 30 日間)
DJ V
DJ V 2016 年 11 月 13 日
回答済み: Steven Lord 2016 年 11 月 14 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by