0

Here is my problem in Matlab:

I have a set of integers e.g. A={10,11,12,...,T} with corresponding densities P={p(10),p(11),P(12),...,P(T)}. How do I randomly sample from A using the weights from P?

tashuhka
  • 5,028
  • 4
  • 45
  • 64
Seb
  • 165
  • 9
  • 1
    possible duplicate of [Weighted random numbers in MATLAB](http://stackoverflow.com/questions/2977497/weighted-random-numbers-in-matlab) – MattG Apr 12 '14 at 02:18

1 Answers1

0

If you have the Statistics Toolbox, you can use randsample.

X = randsample(A, 1, true, P);
Rafael Monteiro
  • 4,509
  • 1
  • 16
  • 28
  • Thanks. Yeah, found a earlier post that helped answer the question too. see: http://stackoverflow.com/questions/2977497/weighted-random-numbers-in-matlab – Seb Apr 12 '14 at 02:16