How to randomize trials without presenting the same trial consecutively
29 views (last 30 days)
I'm a very beginner of Matlab and I'm struggling in randomizing trials in my task on Psychtoolbox, in Matlab. My trials consist in 5 verbal stimuli repeated 12 times (in total 60 trials). I have 2 practice trials and then the 60 testing trials. What I would like to do is to present the practice trial in a fixed order, and the testing trials in a random order, without having the same verbal stimulus repeated consecutively.
My stimulus file (stim.txt) has a column "items" with the stimuli that looks like:
.... x other 11 times (only the testing stimuli are repeated) ....
Here is the part of interest of my code:
%here I define the trial info
trial = 1;
maxTrial = length(stim.items); %this is the excel file from which I take the stimuli
% I define the number of practice trials
%I randomize only the testing trials
This code works, so that I present the practice trials in a fixed order, while the testing trials are randomized. However, when I run the experiment, some testing verbal stimuli are repeated twice or even more times consecutively.
I want to randomize the testing trials without having the same verbal stimulus repeated consecutively.
Can I ask for your help? Thank you very very much!! :)
Megumi Fukuda on 22 Feb 2021
Hopefully it is not too late to answer your question. Randperm generates a vector of random permutation (1, 2, ... n) without duplication. In your case, 7, 12, 17, 22, … indicate “word5” - so if randperm generates a vector such as 12, 7, 22 ...., then the script should display the same words (word5) repeatedly, and that is why you saw the same stimuli on successive trials.
Here is a solution:
Assume you have a stimulus file like this:
and use this code to generate stim sequence
% parameters – change these parameters as you wish
n_word=5; % five words
repeatTime=12; % you wish to present each word for 12 times
n_testTrial=2; % 2 words for practice trials
sequence_testing=[sequence_testing; combinations(round(rand*((n_word-1)*repeatTime)), :)'];
sequence_testing=[sequence_testing; combinations(round(rand*(n_word*repeatTime)), :)'];
TrialIndex=sequence_testing+n_practiceTrial; % shift for practice words
'TrialIndex' can be used for stimulus presentation.
Hope this helps!