Hello List,
I'd like to have responses recorded continuously while various stimuli
are being presented (by recorded I mean (1) the key that was pressed
and (2) the 'reaction time' from trial onset). There is no constraint
as to when the participant is to respond (hence before, during or
after each stimulus is valid). Each trial can be as long as 5 minutes.
I am putting an excerpt of the script below. This is not currently
doing the job. I have tried a couple different ways but somehow I
never get the full set of responses. (i.e. if I test myself and press
10 times a key during the period, only 2 of them might be recorded).
I have tried to change the position of the KbCheck in and out of the
loop, create a timing loop before and including the trial
presentation...I am sure there is a very simple way to do this, but I
can't seem to find it....
Any help would be most appreciated!! Thanks in advance!
(System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
Actual Trial loop:
%%%%%%%%%%%
for i = 1:length(condOrder)
Screen('FillRect',w, black);
drawFixation(FIX_COLOR);
Screen('Flip', w);
if condOrder(i) == 1
deviant = deviantC1;
devname = 'deviantC1';
[...]
else
deviant = deviantD3;
devname = 'deviantD3';
end
% ----- initialization variables ------
idx = 1;
j = 0;
rtime = [];
keyPresses=[];
keyTimes =[];
devTimes = [];
tic;
iterations = 20;
numdeviants = 3;
% randomly determine timing of deviants
tmp = Shuffle(1:5:iterations);
j_rnd = sort(tmp(1:numdeviants));
% ----- end initialization variables ------
k = j_rnd(idx);
TrialTime = GetSecs;
while j <= iterations
k = j_rnd(idx);
[keyIsDown,secs,keyCode]= KbCheck();
keyNumber = getKeyNumber(keyCode); % get numerical value
if ~ isempty(keyNumber)
keyPresses = [keyPresses keyNumber];
keyTimes= [keyTimes secs];
end
if j == k
devTime = GetSecs;
devTimes = [devTimes devTime];
sound (deviant,fs);
idx = idx + 1;
if idx > length(j_rnd)
idx = 1;
end
else
sound(triplet,fs);
end %if
j=j+1;
end %while j
endtime = clock;
%%% sub-function, end of script
%--------------------------------------------------------------------------
function keyNumber = getKeyNumber( keyCode )
global ESC_KEY
keyNumber=[];
for i=1:length(keyCode)
if keyCode(i)
keyName=upper(KbName(i)); %get the key name from the
keyboard key index
if strcmp(keyName, ESC_KEY)
error('ESCAPE key detected');
end
keyNumber=str2num(keyName); %turn the key name into a number
return; %return once the first key pressed is found
end
end
%--------------------------------------------------------------------------
I'd like to have responses recorded continuously while various stimuli
are being presented (by recorded I mean (1) the key that was pressed
and (2) the 'reaction time' from trial onset). There is no constraint
as to when the participant is to respond (hence before, during or
after each stimulus is valid). Each trial can be as long as 5 minutes.
I am putting an excerpt of the script below. This is not currently
doing the job. I have tried a couple different ways but somehow I
never get the full set of responses. (i.e. if I test myself and press
10 times a key during the period, only 2 of them might be recorded).
I have tried to change the position of the KbCheck in and out of the
loop, create a timing loop before and including the trial
presentation...I am sure there is a very simple way to do this, but I
can't seem to find it....
Any help would be most appreciated!! Thanks in advance!
(System: G5, Matlab 7.0.4 and either PsychToolboz v1.0.5 or v1.0.6)
Actual Trial loop:
%%%%%%%%%%%
for i = 1:length(condOrder)
Screen('FillRect',w, black);
drawFixation(FIX_COLOR);
Screen('Flip', w);
if condOrder(i) == 1
deviant = deviantC1;
devname = 'deviantC1';
[...]
else
deviant = deviantD3;
devname = 'deviantD3';
end
% ----- initialization variables ------
idx = 1;
j = 0;
rtime = [];
keyPresses=[];
keyTimes =[];
devTimes = [];
tic;
iterations = 20;
numdeviants = 3;
% randomly determine timing of deviants
tmp = Shuffle(1:5:iterations);
j_rnd = sort(tmp(1:numdeviants));
% ----- end initialization variables ------
k = j_rnd(idx);
TrialTime = GetSecs;
while j <= iterations
k = j_rnd(idx);
[keyIsDown,secs,keyCode]= KbCheck();
keyNumber = getKeyNumber(keyCode); % get numerical value
if ~ isempty(keyNumber)
keyPresses = [keyPresses keyNumber];
keyTimes= [keyTimes secs];
end
if j == k
devTime = GetSecs;
devTimes = [devTimes devTime];
sound (deviant,fs);
idx = idx + 1;
if idx > length(j_rnd)
idx = 1;
end
else
sound(triplet,fs);
end %if
j=j+1;
end %while j
endtime = clock;
%%% sub-function, end of script
%--------------------------------------------------------------------------
function keyNumber = getKeyNumber( keyCode )
global ESC_KEY
keyNumber=[];
for i=1:length(keyCode)
if keyCode(i)
keyName=upper(KbName(i)); %get the key name from the
keyboard key index
if strcmp(keyName, ESC_KEY)
error('ESCAPE key detected');
end
keyNumber=str2num(keyName); %turn the key name into a number
return; %return once the first key pressed is found
end
end
%--------------------------------------------------------------------------