MATLAB: Randomization problem. Is it complicated

rand

Hi all,
A question regarding the randomization with Matlab: I have created a script where I have 12 images and 12 sounds, combined into 24 trials. 1-1 1-2 2-1 2-2 3-3 3-4 4-3 4-4 And so on…. The script works very well and no bugs with psychtoolbox.
Any idea of how to randomise those 24 trials while avoiding 2 consecutive trials? For instance, randomise and avoid 3-4 and 4-4 or 4-3 to occur one after the other.
Looking forward for an answer 🙂
Many thanks!

Best Answer

For something like this, the easiest way is to loop, generating potential orders, exiting the loop if the order is acceptable and otherwise continuing to loop.