Reproduction of datasample with weights

Hello, I want to generate a number vector with 10 elements between 0 and 3. But the vector is not reproducible with my codes: in each iteration, one number will be picked with the probabilities in the corresponding column of lambda. That means, each iteration has a different setting of probabilities. Finally, x is the vector with the 10 elements. How can I get the same vector x, when I run it again? I tried with rng or RandStream, but it didn´t work.
lambda=[0.6 0.6 0.5 0.5 0.4 0.4 0.2 0.2 0.1 0.1 ;
0.2 0.2 0.3 0.3 0.2 0.2 0.2 0.2 0.1 0.1 ;
0.1 0.1 0.1 0.1 0.2 0.2 0.3 0.3 0.4 0.4;
0.1 0.1 0.1 0.1 0.2 0.2 0.3 0.3 0.4 0.4];
for iter= 1: 10
x(iter)=datasample([1 2 3 0],1,'Weights',lambda(:,iter));
end
Thanks a lot for any help!

Antworten (0)

Produkte

Gefragt:

am 10 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by