2017-03-18 57 views
0

我在使用psychtoolbox和准确计时方面存在问题。我按照网站上的教程和PsychDocumentation中的PTBTutorial-ECVP2013.pdf编写了我的代码。但它以某种方式仍然不正确。它需要更长的时间(1或2秒)翻转(超过20秒)。所以我想我在某个地方犯了一个严重的错误,但我找不到它。你能帮我用我的代码吗?精准工具箱准确定时不会在设定框架上翻转

在任何情况下,这就是我的代码的样子。

%Number of seconds to wait (ns) 
nsS = 2; %sentences 
nsW = 1; %words 
nsDot = 7; 
nsWait= 3; 
%Number of frames to wait (wf) before flipping 
wfS = round(nsS/ifi); 
wfW = round(nsW/ifi); 
wfDot = round(nsDot/ifi); 
wfWait = round(nsWait/ifi); 
vbl=Screen('Flip', window); 


for i = 1:10 %1:exp.ntrials 
    sentence = ...; %load sentences 
    word = ...% load words; 

    for iframe = 1:300 
     %draw fixation cross 
     if iframe <= 60 
      DrawFormattedText(window, '+','center','center', white); 
      vbl =Screen('Flip', window, vbl + (wfW-0.5)*ifi); 
     %draw sentence 
     elseif iframe <= 180 
      DrawFormattedText(window, sentence,'center','center', white); 
      vbl = Screen('Flip', window, vbl + (wfS-0.5)*ifi); 
     %blank screen 
     elseif iframe <= 240 
      Screen('FillRect', window, black); 
      vbl = Screen('Flip', window, vbl + (wfW-0.5)*ifi); 
     %Draw word 
     elseif iframe <=300 
      DrawFormattedText(window, word,'center','center', white); 
      vbl = Screen('Flip', window,vbl + (wfW-0.5)*ifi); 
     end 
    end 

    %Draw dot 
    for frames = 1:wfDot 
     Screen('DrawDots', window, [xCenter yCenter], 10, white, [], 2); 
     vbl=Screen('Flip', window, vbl+(wfDot-0.5)*ifi);%, vbl+(wfDot-0.5)*ifi); 
     %WaitSecs(7); 
    end 
    ... 
end 

回答

0

它看起来像你可能使用'iframe'循环遍历屏幕帧?屏幕('翻转')命令将等待在适当的时间呈现刺激,'iframe'循环不需要,是什么导致你的问题。从你的代码修改的例子包含在下面(我不得不添加一些你的例子中没有定义的东西)。将代码包装在try/catch语句中是没有必要的,但在错误时自动关闭屏幕很方便。

try 
    window = Screen('OpenWindow', 0, 0); 
    ifi = Screen('GetFlipInterval', window); 

    %Number of seconds to wait (ns) 
    nsS = 2; %sentences 
    nsW = 1; %words 
    nsDot = 7; 
    nsWait= 3; 
    %Number of frames to wait (wf) before flipping 
    wfS = round(nsS/ifi); 
    wfW = round(nsW/ifi); 
    wfDot = round(nsDot/ifi); 
    wfWait = round(nsWait/ifi); 
    vbl=Screen('Flip', window); 

    black = 0; 
    white = 255; 

    for i = 1:10 %1:exp.ntrials 
     sentence = 'sentence here'; 
     word = 'word here'; 

     DrawFormattedText(window, '+','center','center', white); 
     vbl =Screen('Flip', window, vbl + (wfW-0.5)*ifi); 
     %draw sentence 
     DrawFormattedText(window, sentence,'center','center', white); 
     vbl = Screen('Flip', window, vbl + (wfS-0.5)*ifi); 
     %blank screen 
     Screen('FillRect', window, black); 
     vbl = Screen('Flip', window, vbl + (wfW-0.5)*ifi); 
     %Draw word 
     DrawFormattedText(window, word,'center','center', white); 
     vbl = Screen('Flip', window,vbl + (wfW-0.5)*ifi); 

    end 

    sca; 

catch 
    % close the screen on errors 
    sca; 
end