dimanche 2 mai 2021

Randomizing a vector with certain rules

I am trying to build an experiment where I have specific conditions in certain trials.

Let's assume I have 20 trials, and I have 4 trials where I need to do something different from the rest of them.

diffTrials=[8,12,15,19];
trials=1:20;

for i=1:20
if trials(i)~= diffTrials
disp(sprintf(imageA-%d.jpg',trials(i));)
else
disp(sprintf(imageB-%d.jpg',trials(i));)
end

My aim is to randomize the order of trials without swapping the positions of diffTrials. In other words, I need to have a diffTrials for every participant at 8th 12th ,15th ,and 19th trial. Also, if I am running Condition 1, I want to get 8th or 15th trial as the first diffTrial and others for the Condition 2.

When I run

trials=reshape(trials(randperm(1*20)),1,20);

I get

trials= 18 16 20 7 1 2 8 17 19 15 9 11 13 5 14 4 3 10 12 6

But I need to have 8 or 15 at the trials(1,8) for condition 1, and 12 or 19 for condition 2. The other diffTrials also should located on 12,15 or 19.

For example;

trials= 18 16 20 7 1 2 9 12 11 13 5 15 14 4 19 3 10 17 12 6

is ok since my 8th, 12th, 15th and 19th trials are difTrials...

How can I randomize my trials vectors with such rules?




Aucun commentaire:

Enregistrer un commentaire