Borrar filtros
Borrar filtros

1 and 0 matrix

1 visualización (últimos 30 días)
Offroad Jeep
Offroad Jeep el 5 de Mayo de 2015
Editada: Offroad Jeep el 24 de Mayo de 2015
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...........

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 5 de Mayo de 2015
n = 5; % size your matrix
k = 10; % your percent
out = zeros(n);
out(randperm(n^2,ceil(n^2*k/100))) = 1;
  1 comentario
Offroad Jeep
Offroad Jeep el 5 de Mayo de 2015
thanks...........

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays 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