1

我正在 Matlab 中进行一项心理学实验,其中将向受试者展示带有问题的屏幕。屏幕还将收集和显示受试者的反应。例如:屏幕显示“2+3”并显示参与者类型(例如 99999),直到他们按下回车键。

目标:如果参与者尚未按 Enter,则让它在 16 秒后停止显示问题。(也就是说,如果 time=16sec 或者如果主题按下 Enter,则停止显示屏幕。)

问题围绕以下代码:

    While CurrentTime<TimeOut

    respond=GetChar() <-(Waits till user press enter)

    end

因此,无论我们在捕获响应语句之前/之后添加的任何语句都不会执行。

任何有关如何解决此问题的帮助将不胜感激!谢谢。

4

1 回答 1

2

这是一个例子,我举了一个椭圆作为例子,你显然可以用你的刺激来代替它。Enter 和 Return 是单独的键,我不确定您要查找的是哪个键,因此在示例中循环查找其中任何一个。

%% include at top of experiment / block
waitForResponseSeconds = 16; % number of second to wait for a response
enterKey = KbName('enter'); % numeric code for enter key
returnKeys = KbName('return'); % numeric code for return key(s)
responseKeys = [enterKey returnKeys];

wPtr = Screen('OpenWindow', 0, 0, [0 0 400 400]);


%% within the trial loop:
hasResponded = 0;

% present the stimulus (here the window pointer is called wPtr, you may
% need to adjust this depending on what you named the window pointer.
Screen('FillOval', wPtr, [100 0 100], [0 0 400 400]);

[~, Onset] = Screen('Flip', wPtr);


while ~hasResponded && ((GetSecs - Onset) <= waitForResponseSeconds) 

    [keyIsDown, secs, keyCode] = KbCheck;

    if any(keyCode(responseKeys))
        rt = 1000.*(secs-Onset); % get response time
        hasResponded = 1;
    end

    % Wait 1 ms before checking  again to prevent
    % overload of the machine at elevated priority
    WaitSecs(0.001);
end

%% end of exp
sca;
于 2018-02-03T16:45:52.120 回答