vendredi 13 février 2015

Random permutation of numbers in MATLAB with weights

How to randomize the numbers in a vector a, with weights assigned in such a way that I can control what numbers 'follow' other numbers?


Let's say



a = [ 1 2 3 4]


I would like to obtain something like this:



1 2 1 3 4 2 1 4 3 4 1 3 4 1 ....


My aim is to create a longer vector (including these 1 to 4 numbers, permuted), while adding weights:




  • 1 -> 2, 2 -> 1 (a 2 following a 1 in the vector and vice versa) in 1/3 of cases




  • 3 -> 4, 4 -> 1 (a 3 following a 4 in the vector and vice versa) in 1/3 of cases




  • All other possible transitions, 1/3 of cases




I managed to obtain a longer vector with these numbers permuted, but I do not know how to apply these weights/rules.



Thank you very much.

Aucun commentaire:

Enregistrer un commentaire