matlab - How to terminate a task based on time, regardless of trial number (Psychtoolbox) -
i need make timer starts counting @ beginning of multi-phase delay task, , ends delay task after period of time has passed, moving on next part of experiment. now, i'd end task after 2 seconds have passed.
in code below, included example can paste editor. used part of stroop task delay task consists of 1 phase (in actual code there 3 phases, simplified task question)-- press 1 key red, 2 key green, , 3 key blue. each phase runs 6 trials. (just 1 set of 6 trials 1 phase now).
i'd task (all phases together) last period of time, , terminate @ time set regardless of trial number. if 2 seconds have passed, task should end if on phase 1, trial number 3 of 6.
the code below commented out (while loop numsecondsstart , numsecondsend) current attempt. i'm not sure such loop go (around phase loop, around trial loop?) thanks!
code:
clear close kbname('unifykeynames'); %%%%%%%%%%%%%%%%%%%%%%%%%%%% [window, rect]=screen('openwindow',0); red=kbname('1'); green=kbname('2'); blue=kbname('3'); keysofinterest=zeros(1,256); keysofinterest([red, green, blue])=1; kbqueuecreate(-1, keysofinterest); kbqueuestart; wordcolors = {'red', 'green', 'blue'}; rgbcolors = [1000 0 0; 0 1000 0; 0 0 1000]; starttime=screen('flip',window); kbqueueflush; % numsecondsstart = getsecs; % while (numsecondsend-numsecondsstart) == 1 phase = 1 design=repmat([1 2 3], 2, 2)'; if phase == 1 designrand=design(randperm(length(design)),:); word=wordcolors(designrand(1:6)); color=rgbcolors(designrand(:,2),:); end trial=1:6 if phase == 1 drawformattedtext(window, word{trial}, 'center' ,'center', color(trial,:)); waitsecs(rand+.5) starttime=screen('flip',window); [pressed, firstpress]=kbqueuecheck; endtime=kbqueuewait(); rttext=sprintf('response time =%1.2f secs',endtime-starttime); drawformattedtext(window,rttext,'center' ,'center',[255 0 255]); vbl=screen('flip',window); screen('flip',window,vbl+1); numsecondsend =getsecs; end end end % break; % end listenchar(0); showcursor(); screen('closeall');
i think tic
, toc
friends here...
i not use while
in favour of following: (assuming iteration has started allowed finish)
add tic;
want timing start, not inside loop or else reset timer each iteration.
add following within for
loop, either @ beginning or end
if toc >= 2 break end
this break
out of for
loop first time reaches , 2 seconds or more have passed
Comments
Post a Comment