How to add a time limit to response time?

조회 수: 16 (최근 30일)
Takara Sumoto
Takara Sumoto 2019년 10월 1일
댓글: Takara Sumoto 2019년 10월 2일
I want to add time limit to the response time. I have a code for "wait for response", but I don't know where and what code I should add. (I refered several codes but didn't work) I'm using Psychtoolbox,
%Wait for response
while keyOn == 0
[keyIsDown,secs,keycode] = KbCheck;
if keycode(spaceKey) || keycode(num1Key) || keycode(num2Key) || keycode(num3Key) ...
|| keycode(num4Key) || keycode(num5Key) || keycode(num6Key) ...
|| keycode(num7Key) || keycode(num8Key) || keycode(num9Key)
keyOn = 1;
end
end
Thank you!
  댓글 수: 1
Aquatris
Aquatris 2019년 10월 1일
Can you add tic toc to your code?
You can start a tic and if toc gives you higher than the time limit you break the loop.

댓글을 달려면 로그인하십시오.

채택된 답변

Jeff Miller
Jeff Miller 2019년 10월 1일
One way is to use GetSecs, which returns the current time. For example,
MaxWait = 1.5; % As an example, suppose you want a maximum RT of 1.5 seconds
StopTime = GetSecs + MaxWait; % This computes the time at which you want to stop (max RT)
while (keyOn==0) && (GetSecs<StopTime) % add the time check to your while loop
% The rest of your while loop goes here
end
% You will reach this point if a key is pressed or if MaxWait elapses with no key press.
  댓글 수: 1
Takara Sumoto
Takara Sumoto 2019년 10월 2일
Dear Mr. Miller,
Thank you! It worked perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by