首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用心理工具箱在有限的时间内呈现刺激并仍然记录响应

如何使用心理工具箱在有限的时间内呈现刺激并仍然记录响应
EN

Stack Overflow用户
提问于 2018-08-25 02:51:53
回答 1查看 263关注 0票数 0

对于我的实验,我想向参与者提供一个刺激和一些说明。然后,2秒后,我希望刺激消失,但指令保留,直到参与者做出反应。参与者应该能够在刺激呈现后立即做出反应,并在刺激呈现后最多10秒做出反应。响应时间将被记录下来。

在我目前的代码中,参与者只有在2秒后(刺激消失后)才能做出反应。有没有办法让刺激只出现2秒,而指令仍然留在屏幕上,但参与者能够在刺激呈现后立即做出反应?

代码语言:javascript
复制
%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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-26 04:51:02

不使用WaitSecs()来控制刺激在屏幕上的时间量,而是在响应检查循环中关闭刺激,当适当的时间量过去时。下面的代码片段显示了对上述代码的相关更改。我省略了您如何轮询响应的细节。顺便说一句,我认为您使用'if GetSecs() <= stimTime + 10‘可能无法实现您想要的结果,在您的代码中,此语句将只计算一次,并且始终为真。

代码语言:javascript
复制
% 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52010228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档