1 and 0 matrix

1 次查看(过去 30 天)
Offroad Jeep
Offroad Jeep 2015-5-5
Hi All,..
I want to generate a n by n matrix with 1 and 0 . this matrix should have 10 percent zeros.... in some we cant get exact 10 so + or - 1 or 2 percent will be ok...........

采纳的回答

Andrei Bobrov
Andrei Bobrov 2015-5-5
n = 5; % size your matrix
k = 10; % your percent
out = zeros(n);
out(randperm(n^2,ceil(n^2*k/100))) = 1;

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by