How to randomize trials without presenting the same trial consecutively

조회 수: 6 (최근 30일)
Chiara Saponaro
Chiara Saponaro 2021년 2월 12일
댓글: Amra Feta 2021년 11월 29일
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:
practice1
practice 2
word1
word2
word3
word4
word5
word1
word2
word3
word4
word5
.... 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
NumOfPracticeTrials=2;
%I randomize only the testing trials
TrialIndex(NumOfPracticeTrials+1:maxTrial)=NumOfPracticeTrials+randperm((maxTrial-NumOfPracticeTrials);
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!! :)

답변 (1개)

Megumi Fukuda
Megumi Fukuda 2021년 2월 22일
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:
-----
practice1
practice 2
word1
word2
word3
word4
word5
-----
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
combinations=perms([1:n_word]);
sequence_testing=[]
for idx_repeat=1:repeatTime
if idx_repeat>1
sequence_testing=[sequence_testing; combinations(round(rand*((n_word-1)*repeatTime)), :)'];
else
sequence_testing=[sequence_testing; combinations(round(rand*(n_word*repeatTime)), :)'];
end
tmp_lastNum=sequence_testing(end);
end
TrialIndex=sequence_testing+n_practiceTrial; % shift for practice words
'TrialIndex' can be used for stimulus presentation.
Hope this helps!
  댓글 수: 2
Chiara Saponaro
Chiara Saponaro 2021년 2월 25일
It helped a lot, thank you very much!!
Amra Feta
Amra Feta 2021년 11월 29일
@Megumi Fukuda I have something similar in my case participants are presented with color words written in different ink color. The
participants are required to name the ink color of the stimuli. Each respond of the participant is
recorded as a WAV file in each trial and also the reaction time is recorded.
Every trial includes: a fixation cross presented for 0.5 ms, then the stimulus (color word)
presented for 2 seconds and a blank screen presented 0.5 ms. The voice recording and reaction
time calculation occurs during color word presentation.
The experiment includes several categories of color words presented as jpg image files which are
placed in different folders.
The code chooses a random image from a folder in each trial. However, there is a
possibility that some stimuli with similar features, or the same exact stimulus could be presented
in successive trials. Thus, there is a need of restricting this possibility.
As we talked, this could be done by defining some stimulus clusters and writing “if..else” codes
restricting choosing stimuli from the same clusters in successive trials.
The clusters are the following:
BlueInkColor: MSS.JPG; MCS.JPG; MJS.JPG; MZS.JPG; TMM.JPG; TKM.JPG; TSM.JPG; TYM.JPG
GreenInkColor: MZZ.JPG; MCZ.JPG; MJZ.JPG; MSZ.JPG; TYY.JPG; TKY.JPG; TMY.JPG; TSY.JPG
RedInkColor: MCC.JPG; MJC.JPG; MSC.JPG; MZC.JPG; TKK.JPG; TMK.JPG; TSK.JPG; TYK.JPG
YellowInkColor: MJJ.JPG; MCJ.JPG; MSJ.JPG; MZJ.JPG; TSS.JPG; TKS.JPG; TMS.JPG; TYS.JPG;
BlueColorWord: MSS.JPG; MSC.JPG; MSJ.JPG; MSZ.JPG; TMM.JPG; TMK.JPG; TMS.JPG; TMY.JPG
GreenColorWord: MZZ.JPG; MZC.JPG; MZJ.JPG; MZS.JPG; TYY.JPG; TYK.JPG; TYM.JPG; TYS.JPG
RedColorWord: MCC.JPG; MCJ.JPG; MCS.JPG; MCZ.JPG; TKK.JPG; TKM.JPG; TKS.JPG; TKY.JPG
YellowColorWord: MJJ.JPG; MJC.JPG; MJS.JPG; MJZ.JPG; TSS.JPG; TSK.JPG; TSM.JPG; TSY.JPG
Finally, those images who have the exact same name (e.g., MSS.JPG) should not follow in
successive trials.
Here is the part of the code where I need to add the new code to not repeat the trials.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by