Matlab:向受试者显示屏幕的标准

Matlab: Criteria for displaying screens to subjects

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

目标:如果参与者尚未按下回车键,则让它在 16 秒后停止显示问题。 (也就是说,如果时间 = 16 秒或如果受试者按下 Enter,则停止显示屏幕。)

问题围绕以下代码展开:

    While CurrentTime<TimeOut

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

    end

因此无论我们添加什么语句 before/after 捕获响应语句都不会被执行。

如能提供有关如何解决此问题的任何帮助,我们将不胜感激!谢谢

这是一个例子,我举了一个椭圆作为例子,你显然可以用你的刺激物来代替它。 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;