Randomly picking between two variables

1 visualización (últimos 30 días)
Raminder1992
Raminder1992 el 9 de Mayo de 2011
Hi, I have three variables, BoxA and BoxB. Where BoxA=1, BoxB=2. I would like it so that if I can pick randomly between BoxB and BoxC. Thank you.

Respuestas (1)

Walter Roberson
Walter Roberson el 9 de Mayo de 2011
What is BoxC ??
Anyhow, to pick N by M random values from a list:
rvals = [BoxA, BoxB]; %expand the list if you have reason
randompicks = rvals(ceil(rand(N, M) * length(rvals)));
I believe there is also a Stats toolbox function to do random sampling of exactly this kind.

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by