title: (Roulette Wheel) Sorting multiple elements in an array
body: <p>I'm perfoming a Roulette Wheel selection (<a href="http://www.edc.ncl.ac.uk/assets/hilite_graphics/rhjan07g02.png" rel="nofollow noreferrer">http://www.edc.ncl.ac.uk/assets/hilite_graphics/rhjan07g02.png</a>), and I want to compute the selection of <code>n</code> elements. How can I do this avoiding the use of loops?</p>
  
  <p>For example, I have the following <code>prob</code> vector: </p>
  
  <pre><code>prob = [0.1 0.3 0.4 0.15 0.05];
  </code></pre>
  
  <p>The selection of a single <code>element=0.2</code> would be:</p>
  
  <pre><code>cumprob = cumsum(prob);
  selected = find(element&lt;=prob,1,'first')
  </code></pre>
  
  <blockquote>
    <p>selected = 2</p>
  </blockquote>
  
  <p>But, what about computing the selection of <code>n</code> elements? The intuitive and slow way would be:</p>
  
  <pre><code>cumprob = cumsum(prob);
  for id = 1:1:n 
     selected(id) = find(element(id)&lt;=prob,1,'first');
  end
  </code></pre>
  
  <p>Is there any way to implement this avoiding the use of the for loop?</p>
  
  <p>Thanks in advance.</p>