Albrecht2019 / scripts /Practice_test.m
jalauer's picture
Add files using upload-large-folder tool
e7dce60 verified
%*****Block1 STIM SETUP****
% the number of trials of each stim pairing
B1trials_perType = 2;
% build the B1 trial list
AB_trials = repmat([ A,B ], B1trials_perType, 1);
BA_trials = repmat([ B,A ], B1trials_perType, 1);
% bind all the trial types to define the block's trials
B1_trialList = [AB_trials; BA_trials;];
% read in the images and create the required textures: {A,B}
B1_images = [];
B1_images{1} = imread('./images/1.bmp');
B1_images{2} = imread('./images/2.bmp');
% load all the textures
B1_textures = [];
for B1Texture_index = 1 : size(B1_images, 2) % Number of stims
B1_textures{B1Texture_index}= Screen('MakeTexture', wPtr, B1_images{B1Texture_index});
end
% load the textures into an array mapping onto corresponding choice ids
textures = [];
textures(A) = B1_textures{1}; % {A,B}
textures(B) = B1_textures{2};
%****BEGIN B1_test*****
B1Complete = false;
numB1Blocks = 1; %*******Determines # of Blocks*******
B1block_index = 0;
no_response = false;
% loop through the B1 phase
while ~B1Complete
% track trial ids
trial_ids = [];
% track trial type
trial_stimuli = [];
%track response
trial_response = [];
% track which stim was choosen
trial_selectedStim = [];
% track the rt
trial_RT = [];
% track the accuracy
trial_accuracy = [];
% increment the block index
B1block_index = B1block_index + 1;
% random_index = randperm(size(B1_trialList, 1));
randomized_trialList = B1_trialList([1,3,2,4],:); %(random_index,:);
trial_index = 1;
while trial_index <= size(randomized_trialList, 1)
% Fixation
fixation_text = '+';
Screen('TextFont',wPtr,'Times');
Screen('TextStyle',wPtr,0);
Screen('TextColor',wPtr,[255 255 255]);
Screen('TextSize',wPtr,80);
DrawFormattedText(wPtr,fixation_text,'center','center');
Screen(wPtr, 'Flip');
% show the fixation for 1 sec
WaitSecs(1);
% get the current trial's info
L = randomized_trialList(trial_index, 1);
R = randomized_trialList(trial_index, 2);
% NetStation('Event',trial_pair,EventTime+offset - (1.81e-05)*(EventTime -
% Synchtime)););
% define the correct choice
if L==1 || L==3 % A or C
correct_choice = left_button;
% correct_choice = up_key;
elseif L==2 || L==4 % B or D
correct_choice = right_button;
% correct_choice = down_key;
end
%rect=[left_rect_test',right_rect_test'];
%rect=[down_rect',up_rect']; % For some reason need to be reversed
% now draw the stim
Screen('DrawTexture', wPtr, textures(L), [], left_rect_test);
Screen('DrawTexture', wPtr, textures(R), [], right_rect_test);
Screen(wPtr, 'Flip');
% start the trial timer;
startTime = GetSecs();
wait_stamp=GetSecs;
% display "tmp"
while 1
% [a ab] = JoyMEX(0);
[ keyIsDown, seconds, keyCode ] = KbCheck(GPindx);
if keyIsDown
if keyCode(left_button) && left_button==correct_choice
subject_choice = left_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 1;
break;
elseif keyCode(right_button) && right_button==correct_choice
subject_choice = right_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 1;
break;
elseif keyCode(left_button) && left_button~=correct_choice % supoptimal
subject_choice = left_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 0;
break;
elseif keyCode(right_button) && right_button~=correct_choice % supoptimal
subject_choice = right_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 0;
break;
end
elseif(GetSecs-wait_stamp) > TSTDEADLINE,
subject_choice = 9999;
no_response = true;
trlResponse = -1;
trlAccuracy = -1;
break;
end
end
% stop the trial timer
RT = GetSecs() - startTime;
% determine if they selected the right or left stim
if subject_choice == correct_choice
trlselectedStim = 1;
else
trlselectedStim = 0;
end
% determine the reward feedback
Screen('TextSize',wPtr,70);
Screen('TextFont',wPtr,'Times');
Screen('TextStyle',wPtr,1);
% Store the trial data
%
% update the trial number list
trial_ids = [trial_ids; trial_index];
% store the trial stimuli
trial_stimuli = [trial_stimuli; randomized_trialList(trial_index,:)];
%store response
trial_response = [trial_response; trlResponse];
% store the RT
trial_RT = [trial_RT; RT];
% store the subject's choice
trial_selectedStim = [trial_selectedStim; trlselectedStim];
% store accuracy independent of feedback
trial_accuracy = [trial_accuracy; trlAccuracy];
% increment the trial index
trial_index = trial_index + 1;
end
% check to see if B1 is done
if B1block_index >= numB1Blocks
B1Complete = true;
end
end
% *****END OF B1_test*****