如何在有限的时间内呈现刺激并仍然使用 Psychtoolbox 记录反应
How to present stimulus for limited amount of time and still record response using Psychtoolbox
对于我的实验,我想向参与者提供刺激和一些说明。然后 2 秒后,我希望刺激消失,但指令保留,直到参与者做出反应。参与者应该能够在刺激呈现后立即做出反应,并在刺激呈现后最多 10 秒内做出反应。将记录响应时间。
使用我当前的代码,参与者要等到 2 秒后(刺激消失后)才能做出反应。有没有什么办法可以让刺激只出现 2 秒,而指令仍然在屏幕上,但参与者能够在刺激呈现后立即做出反应?
%Show the instructions and the stimulus
Screen('DrawTexture', window, randFaceTexture2);
DrawFormattedText(window, [instructions1], 'center', 600)
stimTime = Screen('Flip', window);
WaitSecs(2);
%Stimulus disappears but instructions remain
DrawFormattedText(window, [instructions1], 'center', 600)
Screen('Flip', window);
if GetSecs() <= stimTime + 10
keyIsDown = 0;
startTime = GetSecs();
while 1
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
nKeys = sum(keyCode);
if nKeys == 1
if keyCode(yes) || keyCode(no)
reactionTime = 1000*(GetSecs - startTime);
response = KbName(keyCode);
Screen('Flip', window);
break;
elseif keyCode(escKey)
ShowCursor;
fclose(outfile);
Screen('CloseAll');
return
end
keyIsDown = 0;
keyCode = 0;
end
end
end
else
line3 = 'Sorry you''re out of time';
DrawFormattedText(window, line3, 'center', 'center');
Screen('Flip', window);
keyIsDown = 0;
rt = 0;
end
不要使用 WaitSecs()
来控制刺激物在屏幕上显示的时间,而是在经过适当的时间后,在响应检查循环中关闭刺激物。这是一个片段,显示了对上述代码的相关更改。我省略了您如何轮询响应的详细信息。顺便说一句,我认为您对 'if GetSecs() <= stimTime + 10' 的使用可能无法实现您想要的,在您的代码中,该语句只会被评估一次,并且永远为真。
% time in seconds for the stimulus to remain onscreen
timeForStimulus = 2;
% time for the participant to respond, in seconds
timeToRespond = 10;
%Show the instructions and the stimulus
Screen('DrawTexture', window, randFaceTexture2);
DrawFormattedText(window, [instructions1], 'center', 600)
stimTime = Screen('Flip', window);
stimOnScreen = 1;
while GetSecs() <= (stimTime + timeToRespond)
% turn the stimulus off, if the stim is on and the stim time has elapsed
if (stimOnScreen == 1) && (GetSecs() > (stimTime + timeForStimulus))
%Stimulus disappears but instructions remain
DrawFormattedText(window, [instructions1], 'center', 600)
Screen('Flip', window);
stimOnScreen = 0;
end
% poll for keyboard response, etc.
end
对于我的实验,我想向参与者提供刺激和一些说明。然后 2 秒后,我希望刺激消失,但指令保留,直到参与者做出反应。参与者应该能够在刺激呈现后立即做出反应,并在刺激呈现后最多 10 秒内做出反应。将记录响应时间。
使用我当前的代码,参与者要等到 2 秒后(刺激消失后)才能做出反应。有没有什么办法可以让刺激只出现 2 秒,而指令仍然在屏幕上,但参与者能够在刺激呈现后立即做出反应?
%Show the instructions and the stimulus
Screen('DrawTexture', window, randFaceTexture2);
DrawFormattedText(window, [instructions1], 'center', 600)
stimTime = Screen('Flip', window);
WaitSecs(2);
%Stimulus disappears but instructions remain
DrawFormattedText(window, [instructions1], 'center', 600)
Screen('Flip', window);
if GetSecs() <= stimTime + 10
keyIsDown = 0;
startTime = GetSecs();
while 1
[keyIsDown, secs, keyCode] = KbCheck;
FlushEvents('keyDown');
if keyIsDown
nKeys = sum(keyCode);
if nKeys == 1
if keyCode(yes) || keyCode(no)
reactionTime = 1000*(GetSecs - startTime);
response = KbName(keyCode);
Screen('Flip', window);
break;
elseif keyCode(escKey)
ShowCursor;
fclose(outfile);
Screen('CloseAll');
return
end
keyIsDown = 0;
keyCode = 0;
end
end
end
else
line3 = 'Sorry you''re out of time';
DrawFormattedText(window, line3, 'center', 'center');
Screen('Flip', window);
keyIsDown = 0;
rt = 0;
end
不要使用 WaitSecs()
来控制刺激物在屏幕上显示的时间,而是在经过适当的时间后,在响应检查循环中关闭刺激物。这是一个片段,显示了对上述代码的相关更改。我省略了您如何轮询响应的详细信息。顺便说一句,我认为您对 'if GetSecs() <= stimTime + 10' 的使用可能无法实现您想要的,在您的代码中,该语句只会被评估一次,并且永远为真。
% time in seconds for the stimulus to remain onscreen
timeForStimulus = 2;
% time for the participant to respond, in seconds
timeToRespond = 10;
%Show the instructions and the stimulus
Screen('DrawTexture', window, randFaceTexture2);
DrawFormattedText(window, [instructions1], 'center', 600)
stimTime = Screen('Flip', window);
stimOnScreen = 1;
while GetSecs() <= (stimTime + timeToRespond)
% turn the stimulus off, if the stim is on and the stim time has elapsed
if (stimOnScreen == 1) && (GetSecs() > (stimTime + timeForStimulus))
%Stimulus disappears but instructions remain
DrawFormattedText(window, [instructions1], 'center', 600)
Screen('Flip', window);
stimOnScreen = 0;
end
% poll for keyboard response, etc.
end