Generating a random number from an already given n values
Mostrar comentarios más antiguos
Hallo,
Given n values e.g x=[ 1 3 4 6 7] I want to be able to generate one amongst them randomly every time I call up a custom function. Is there a way this can be accomplished with the rand function? I have tried reading rand help doc and can't make much out of it. Will really appreciate an answer.
Respuestas (1)
Image Analyst
el 17 de Abr. de 2013
Try this:
randomX = x(randi(length(x)))
2 comentarios
Marvin Leo
el 19 de Abr. de 2013
Image Analyst
el 19 de Abr. de 2013
You're welcome. Please go ahead and officially mark the answer as "Accepted".
Categorías
Más información sobre MATLAB 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!