How to select k out of n, k being normally distributed but not exceeding n

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.

답변 (1개)

Matt J
Matt J 2014년 5월 13일
편집: Matt J 2014년 5월 13일

0 개 추천

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

Daniel
Daniel 2014년 5월 13일
편집: Daniel 2014년 5월 13일
Thank you for the first part.
k should be normally distributed integer over the range 1 to n-1. Initially I ran into problems when k exceeded n and I solved it by decreasing the standard deviation. I am not happy with this, as it still leaves the problem unsolved. Do you have an idea how to do this better?
Edit: nchoosek is sadly not what I need. I don't need the binomial coefficient. I need one set of k numbers froom 0 to n.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

질문:

2014년 5월 13일

댓글:

2014년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by