【问题标题】:Matlab: Criteria for displaying screens to subjectsMatlab:向主题显示屏幕的标准
【发布时间】:2018-07-10 22:45:57
【问题描述】:

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

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

问题围绕以下代码:

    While CurrentTime<TimeOut

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

    end

所以我们在捕获响应语句之前/之后添加的任何语句都不会执行。

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

【问题讨论】:

  • 很可能你遇到了 while 条件的问题。你是如何定义当前时间和超时时间的?
  • 点击按钮等其他选项可以吗?

标签: matlab while-loop conditional psychtoolbox


【解决方案1】:

这是一个示例,我以椭圆形为例,您显然可以将其替换为您的任何刺激。 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;

【讨论】:

    猜你喜欢
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 2011-12-14
    • 1970-01-01
    相关资源
    最近更新 更多