File size: 5,976 Bytes
e7dce60 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
%*****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***** |