Clear Filters
Clear Filters

Randomization of equal number of trials between two different conditions

2 views (last 30 days)
I designed a experiment where I have total 280 trials, divided into two different conditions of 140 trials each. After each 70 trials I am presenting BREAK to the particiapnts. I have total 7 durations (50,100,150,200,250,300,350 ms), each should be presented for 20 times making it 140 for 1 condition. Similarly for other condition, thus total is 280. All the seven durations are presented for 40 times in total for whole experiment. When I run the code, the durations are randomized among all 280 trials ( it means, lets say for a particular duration ex. 50 ms , it is showing for 25 times in 1st condition and 15 times for the second condition). I want to do analysis seperately for two different conditions, so i want that all the seven durations should be randomized equally (20 times each) for 140 trials (1st condition) and similarly all the seven durations should be randomized equally (20 times each) for the next 140 trials (2nd condition).
the below is the code---
%% this is how i have randomized the trials
Trial_Number = (1:280); % Serial Number of trials
% Delay_time is a variable that will take up 10 random values among
% (0.05,0.1,0.15,0.2,0.25,0.3,0.35s- 7 random duration values)
Delay_time = zeros(1,280);
Delay_time (1:40) = 0.05;
Delay_time (41:80) = 0.1;
Delay_time (81:120) = 0.15;
Delay_time (121:160) = 0.2;
Delay_time (161:200) = 0.25;
Delay_time (201:240) = 0.3;
Delay_time (241:280) = 0.35;
Delay_time = Delay_time (randperm(280))*1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRIAL STRUCTURE %%%%%%%%%%%%%%%%%%%%%%%%%%%%
start = GetSecs;
for i_trial = 1:70
% curr = GetSecs; %Gets current time
% disp(curr-start); %Displays time since
% start=curr;
% Draw the fixation cross in white, set it to the center of our screen and % set good quality antialiasing
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
% Flip to the screen
Screen('Flip', window);
% Wait for 500 ms
WaitSecs (0.5);
% Draw the rect to the screen
Screen('FrameOval', window, rectColor, centeredRect, maxDiameter);
% Flip to the screen
Screen('Flip', window);
WaitSecs (Delay_time (i_trial)); % random durations for which oval to be presented on screen
% Screen('FillOval', window, [0 0 0], centeredRect); %blank screen
% Screen('Flip', window);
% WaitSecs (1); %Wait for 1 sec
DrawFormattedText(window, 'Closer to Shorter or Longer duration?', 'center', 'center', white); % Question asked to Participants
Screen('Flip', window)
% KbWait; % Wait for taking responses from participants
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Accepting mouse responses from Participants %%%%%%%%%%%%%%%%%%%%%%%%%%%%
while 1
%
% % read the current status of the keyboard
% [buttons] = GetMouse;
[x1,y1,buttons,~,~,~] = GetMouse(); % buttons is a logical variable[0 0 0]. A value of '1' will be shown if corresponding button is pressed. If left button is pressed, it will be like [1 0 0]
% If middle button is pressed, it will be like [0 1 0]
% If right button is pressed, it will be like [0 0 1]
if buttons(1)== 1 % buttons (1) means left mouse button. If left mouse button value is equals to 1
Mouse_Button_Pressed(i_trial)= 1 ; % then, Mouse_Button_Pressed for current trial value will be 1. 1 in this statement reflects 'left mouse button'.
break;
end
if buttons(3) == 1 % buttons (3) means right mouse button. If right mouse button value is equals to 1
Mouse_Button_Pressed(i_trial)= 2 ; %then, Mouse_Button_Pressed for current trial value will be 2. 2 in this statement reflects 'right mouse button'.
break;
end
end
% DrawFormattedText(window,['BREAK\n\n'...
% 'Press any key to continue.'], 'center', 'center', white);
% Screen('Flip', window);
% KbWait;
end
DrawFormattedText(window,['You can relax now \n\n'...
'When you get ready, press any key to continue'], 'center', 'center', white);
Screen('Flip', window);
KbWait;
start = GetSecs;
for i_trial = 71:140
% curr = GetSecs; %Gets current time
% disp(curr-start); %Displays time since
% start=curr;
% Draw the fixation cross in white, set it to the center of our screen and % set good quality antialiasing
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
% Flip to the screen
Screen('Flip', window);
% Wait for 500 ms
WaitSecs (0.5);
% Draw the rect to the screen
Screen('FrameOval', window, rectColor, centeredRect, maxDiameter);
% Flip to the screen
Screen('Flip', window);
WaitSecs (Delay_time (i_trial)); % random durations for which oval to be presented on screen
% Screen('FillOval', window, [0 0 0], centeredRect); %blank screen
% Screen('Flip', window);
% WaitSecs (1); %Wait for 1 sec
DrawFormattedText(window, 'Closer to Shorter or Longer duration?', 'center', 'center', white); % Question asked to Participants
Screen('Flip', window)
% KbWait; % Wait for taking responses from participants
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Accepting mouse responses from Participants %%%%%%%%%%%%%%%%%%%%%%%%%%%%
while 1
%
% % read the current status of the keyboard
% [buttons] = GetMouse;
[x1,y1,buttons,~,~,~] = GetMouse(); % buttons is a logical variable[0 0 0]. A value of '1' will be shown if corresponding button is pressed. If left button is pressed, it will be like [1 0 0]
% If middle button is pressed, it will be like [0 1 0]
% If right button is pressed, it will be like [0 0 1]
if buttons(1)== 1 % buttons (1) means left mouse button. If left mouse button value is equals to 1
Mouse_Button_Pressed(i_trial)= 1 ; % then, Mouse_Button_Pressed for current trial value will be 1. 1 in this statement reflects 'left mouse button'.
break;
end
if buttons(3) == 1 % buttons (3) means right mouse button. If right mouse button value is equals to 1
Mouse_Button_Pressed(i_trial)= 2 ; %then, Mouse_Button_Pressed for current trial value will be 2. 2 in this statement reflects 'right mouse button'.
break;
end
end
end
DrawFormattedText(window,['Welcome to the 2nd part of the Experiment\n\n'...
'Keep both the hands on your lap\n\n'...
'When you get ready, press any key to continue'], 'center', 'center', white);
Screen('Flip', window);
KbWait;

Answers (1)

vidyesh
vidyesh on 27 Oct 2023
Hi ANKIT,
Based on my understanding, you aim to generate a total of 280 trials, divided into two distinct conditions. Furthermore, it is essential that each condition contains an equal number of instances for each duration, specifically 20 occurrences for each duration in both conditions.
To accomplish this, I suggest the following approach:
  1. Create an array of length 140: Begin by initializing an array with a length of 140. This array will accommodate 20 trials for each duration.
  2. Assign durations to the array: Assign the desired durations to the array, ensuring that each duration is represented 20 times. This can be achieved using a loop or a combination of array indexing and repetition.
  3. Perform two rounds of randomization: Randomize the array twice to obtain distinct sets of trials for each condition. This process will ensure that the trials are arranged differently in each condition.
By following these steps, you will successfully generate a collection of 280 trials, divided into two conditions. Both conditions will contain an equal number of instances for each duration, with each duration appearing precisely 20 times in each condition.
Delay_time = zeros(1,140);
Delay_time (1:20) = 0.05;
Delay_time (21:40) = 0.1;
Delay_time (41:60) = 0.15;
Delay_time (61:80) = 0.2;
Delay_time (81:100) = 0.25;
Delay_time (101:120) = 0.3;
Delay_time (121:140) = 0.35;
Delay_time1 = Delay_time (randperm(140))*1
Delay_time2 = Delay_time (randperm(140))*1
Delay_time = [Delay_time1 Delay_time2] % Concatenate the arrays if necessary.
Refer to the following documentation for more details:
Hope this answer helps

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!