How to select k out of n, k being normally distributed but not exceeding n
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I need to select k numbers out of n without generating doubles and k must not exceed n.
I used to do it by first getting k with normrnd and a very low variation and then finding random numbers and checking for doubles until I have my set of k. Not a very nice approach I know.
Just now I found randperm and it allows me to do this more elegantly, but the prime use of that function, the permutation, is wasted effort in my use. I also switched from normrnd(mu,sigma) to mu+sigma*randn.
Does anyone know a more fficient way of doing this?
Thank you.
0 个评论
回答(1 个)
Matt J
2014-5-13
编辑:Matt J
2014-5-13
There is nchoosek(n,k).
It's not clear, however, what "k being normally distributed" is supposed to mean. Clearly, k is always a positive integer, so it cannot be normally distributed.
2 个评论
Matt J
2014-5-13
I still have no idea what a "normally distributed integer" means. It is definitely not standard terminology. Perhaps you mean a uniformly distributed integer, in which case you could use RANDI.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!