0

我正在尝试记录参与者对需要在固定持续时间(500 毫秒)内显示的视觉刺激的反应。但是,我还想在刺激开始后的 1 秒时间窗口内记录他们在这个固定持续时间后的反应。以下代码仅允许我在刺激呈现期间(500 毫秒)按下键时记录响应。

    StimulusSecs = 0.50001;
    StimDuration = round(StimulusSecs / ifi);
    ISISecs = 0.50001;
    ISI = round(ISISecs / ifi);
    ITISecs = [1.00001, 2.00001, 3.00001];
    intertrial = round(ITISecs / ifi);
    waitframes = 1;
    vbl = Screen('Flip', mainwin);
    t2wait = 1;

    [~, Onset]=Screen('Flip', mainwin); keyIsDown=0; rt=0;

    tic % Stimulus Onset

    for frame = 1:StimDuration
    Screen('DrawTexture', mainwin, pics(picCounter));
    vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);
    [keyIsDown, secs, keyCode] = KbCheck;
    FlushEvents('keyDown');
    if keyIsDown
        if keyCode(spaceKey)
            rt = 1000.*(secs-Onset);
            keypressed=find(keyCode); 
            % break; is missing as this would 
            % escape the loop
        elseif (secs-Onset) > t2wait
            break;
        elseif keyCode(escKey)
            ShowCursor; fclose(outfile); Screen('CloseAll');
            return;
        end
        keyIsDown=0; keyCode=0; keypressed=0;
    end
end
S2dur = toc;

我是psychoolbox的新手,任何帮助将不胜感激!!!

4

2 回答 2

0

我假设picCounter在给定试验的整个 1 秒时间内保持不变。我认为您可以通过更改循环以使其继续查询键盘 1 秒来实现您所需要的,但添加一个条件以便显示的内容取决于经过了多少时间。

start_time = GetSecs; % stimulus onset
while GetSecs-start_time<1

    % draw stimulus only if elapsed time is < 0.5 sec
    if GetSecs-start_time<0.5
        Screen('DrawTexture', mainwin, pics(picCounter));
    end
    vbl = Screen('Flip',mainwin, vbl + (waitframes - 0.5) * ifi);

    % proceed by querying keyboard, etc.
    [keyIsDown, secs, keyCode] = KbCheck;

    (...)

end
于 2018-01-11T08:08:51.637 回答
0

您目前正在为每一帧重新绘制和重新翻转刺激。如果这些是静态图像,则不需要这样做,因为您只需要在想要更改屏幕上的内容时重新绘制和翻转。这是一个假设静态图像的示例。关键响应循环在整个 t2wait 期间运行。在该循环中,条件语句比较分配给刺激的时间是否已过,如果已过,则将其从屏幕上删除:

StimulusSecs = 0.50001;
StimDuration = round(StimulusSecs / ifi);
ISISecs = 0.50001;
ISI = round(ISISecs / ifi);
ITISecs = [1.00001, 2.00001, 3.00001];
intertrial = round(ITISecs / ifi);
waitframes = 1;
vbl = Screen('Flip', mainwin);
t2wait = 1;

tic % Stimulus Onset

[~, Onset] = Screen('DrawTexture', mainwin, pics(picCounter));
OnScreen = 1; % variable to indicate whether the stim is still onscreen
keyPressed = 0; % variable will be 0 until the space key is pressed
rt=0;
while (GetSecs - Onset) <=  t2wait

    [keyIsDown, secs, keyCode] = KbCheck;

    if keyPressed == 0 && keyIsDown
        if keyCode(spaceKey)
            rt = 1000.*(secs-Onset);
            keypressed=find(keyCode);
        elseif keyCode(escKey)
            ShowCursor; fclose(outfile); Screen('CloseAll');
            return;
        end
    end

    % turn the stimulus off if StimulusSecs has elapsed
    if OnScreen == 1 && ((GetSecs - Onset) >= StimulusSecs)
        Screen('Flip',wPtr);
        OnScreen = 0;
    end

    % Wait 1 ms before checking  again to prevent
    % overload of the machine at elevated priority
    WaitSecs(0.001);
end
于 2018-01-11T17:54:18.197 回答