Randomly picking between two variables

3 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2011-5-9
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.

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by