How to generate a a restricted binary number
Mostrar comentarios más antiguos
Dear friends
I would like to generate a random number include 24 bits 4 bits of 1 and 20 bits of 0. Can you help me?
Best Regards
Mohsen
Respuesta aceptada
Más respuestas (1)
2 comentarios
I do not understand what "number dimension, max and min" means. Maximum and minimum of what? My answer includes a method to create random vectors already:
v = zeros(1, 24);
v(randperm(24, 4)) = 1;
Do you now want to create all these vectors? Then:
M = nchoosek(1:24, 4);
for k = 1:size(M, 1)
v = zeros(1, 24);
v(M(k, :)) = 1;
...
end
Mohsen
el 6 de Dic. de 2018
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!