 real values</span>
0032 <span class="comment">% return an integer c between 1 and length(w) with probability proportional</span>
0033 <span class="comment">% to w(c).</span>
0034 
0035 n = length(w);
0036 p = cumsum(w);
0037 p = p/p(n);
0038 c = sum(p&lt;rand)+1;</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>