random number generator
Mostrar comentarios más antiguos
hi...
Can i know how to create a vector with specific number of 1 value? Example i have 5 x 1 matrix, then i want to assign value 1 randomly, but i only want 3 numbers or less of 1's in that matrix..
such as: 1 0 1 1 0
or 0 1 1 0 0
Thanks
Respuesta aceptada
Más respuestas (1)
Junaid
el 27 de Nov. de 2011
1 voto
Let say you have matrix A of 5x1. And you want three of them to be one number. So generate three number
r = round( rand(3,1) * 3 ); % r will have random number between 0-3
now
A(r) = 1; % let say you want to them to be 1
Remember that in random number you can get repeating as well.
1 comentario
lhyin5277
el 27 de Nov. de 2011
Categorías
Más información sobre Random Number Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!