% code to run a simple oddball paradigm % O. Krigolson June 15, 2018 clear all; % clears all variables close all; % closes all files clc; % clear screen HideCursor; % hide the cursor rng('shuffle'); % this seeds the random number generator to be based on the clock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% numberOfBlocks = 1; % define the number of blocks numberOfTrials = 200; % define the number of trials [win, rect] = Screen('OpenWindow', 0, [0 0 0],[0 0 400 400], 32, 2); % Set up graphics window xMid = round(0.5*(r1(3)-r1(1))); % determine the x midpoint of the screen yMid = round(0.5*(r1(4)-r1(2))); % determine the y midpoint of the screen oddBallColour = [255 0 0]; % the oddball colour controlColour = [0 255 0]; % the control colour trialType(1:50) = 1; % oddball trials trialType(51:200) = 2; % control trials trialType = shuffle(trialType); % randomize it %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MAIN PROGRAM LOOP % loop through the number of blocks for blockCounter = 1:numberOfBlocks % loop through the number of trials for trialCounter = 1:numberOfTrials % determine the trial type for the current trial currentTrialType = trialType(trialCounter); % draw a small square as a fixation cross Screen(win,'FillRect',[255 255 255],[xMid-5 yMid-5 xMid+5 yMid+5]); Screen('Flip', win); % wait for some amount of time fixationTime = 0.4 + rand(1)*0.2; WaitSecs(fixationTime); % draw either the oddball or control square dependent on the % current trial type if currentTrialType == 1 Screen(win,'FillRect',oddBallColour,[xMid-20 yMid-20 xMid+20 yMid+20]); else Screen(win,'FillRect',controlColour,[xMid-20 yMid-20 xMid+20 yMid+20]); end Screen('Flip', win); % send markers HERE... EEG experiments ONLY! if currentTrialType == 1 % SEND ODDBALL MARKER else % SEND CONTROL MARKER end % wait for some amount of time circleTime = 0.8 + rand(1)*0.2; WaitSecs(circleTime); end end screen('CloseAll'); % Close all PsychToolbox windows. ShowCursor; % Put cursor back on.