0

我正在尝试使用 Psychtoolbox 在 MATLAB R2014b 中创建一个简单的 RT 实验。参与者必须对面孔进行分类,尽可能快地按下两个按钮之一。我在一台计算机上创建了范例,它运行良好,但是当我将它移到另一台(我想要测试的那个)上时,出现了一个奇怪的错误:即使程序似乎正在记录按键大多数试验,有时它不会响应,我必须按几次键才能进行下一次试验。我不确定发生了什么,但我认为计算机本身可能有问题(可能是什么?),或者代码的这个特定位:

    Screen('Flip', mainwin);
    timeStart = GetSecs;keyIsDown=0; correct=0; rt=0;
    while 1
        bf = 0; %this variable is irrelevant here, I use it later to break 
        out of a loop 
        while (GetSecs - timeStart) < 0.2 %faces are presented briefly, but 
        %I'm recording responses here anyway, just in case there are some 
        %fast anticipatory responses - after this loop is over, I keep 
        %recording RT and button press the exact same way, but with no 
        %stimulus present
            [keyIsDown, secs, keyCode] = KbCheck;
            FlushEvents('keyDown');
            if keyIsDown
                nKeys = sum(keyCode);
                if nKeys==1
                    if keyCode(Key1)||keyCode(Key2)
                        rt = 1000.*(GetSecs-timeStart);
                        keypressed=find(keyCode);
                        Screen('Flip', mainwin);
                        type = 'T';
                        bf = 1;
                        if keyCode(Key1) & targ_pic == 1
                            correct = 1;
                        elseif keyCode(Key2) & targ_pic == 0
                            correct = 1;
                        end
                        break;
                    elseif keyCode(escKey)
                        ShowCursor; fclose(outfile);  Screen('CloseAll'); 
                        return
                    end
                    keyIsDown=0; keyCode=0;
                end
            else
                keypressed = 0; 
            end
        end

谁能发现这可能有问题?

顺便说一句:这是让 RT 退出 PTB 的正确方法吗?我在网上找到了那段代码,但我有点不确定为什么不使用“secs”变量。

两台计算机都运行 Windows 10。

4

1 回答 1

1

A few suggestions:

The Flip command will return the estimate of stimulus onset time, currently you are calling GetSecs after the Flip command, which is not necessary and will always return a value that is slightly later than the actual screen Flip. Likewise, you can use the time of key press returned by KbCheck, rather than calling GetSecs after identifying a key press.

I don't think you need the FlushEvents command, and it might be causing some timing variability.

It is also sometimes useful to pause for a short amount of time (for example 1 millisecond) between KbCheck events.

Below is a version of your code snippet with a few of these changes. It may also be more concise to have a single response checking loop, in which you Flip off the stimulus after 200 ms, rather than separate pre 200 ms and post 200 ms response checking loops, though I haven't made that change here.

keyIsDown=0; correct=0; rt=0;
[~, timeStart] = Screen('Flip', mainwin);
while 1
    bf = 0; %this variable is irrelevant here, I use it later to break
    %out of a loop
    while (GetSecs - timeStart) < 0.2 %faces are presented briefly, but
        %I'm recording responses here anyway, just in case there are some
        %fast anticipatory responses - after this loop is over, I keep
        %recording RT and button press the exact same way, but with no
        %stimulus present
        [keyIsDown, secs, keyCode] = KbCheck;
        if keyIsDown
            nKeys = sum(keyCode);
            if nKeys==1
                if keyCode(Key1)||keyCode(Key2)
                    rt = 1000.*(secs-timeStart);
                    keypressed=find(keyCode);
                    Screen('Flip', mainwin);
                    type = 'T';
                    bf = 1;
                    if keyCode(Key1) & targ_pic == 1
                        correct = 1;
                    elseif keyCode(Key2) & targ_pic == 0
                        correct = 1;
                    end
                    break;
                elseif keyCode(escKey)
                    ShowCursor; fclose(outfile);  Screen('CloseAll');
                    return
                end
                keyIsDown=0; keyCode=0;
            end
        else
            keypressed = 0;
        end
        WaitSecs(.001);
    end
end
于 2017-05-13T15:20:31.927 回答