how to implement matlab count
이전 댓글 표시
I am very much a beginner at matlab and have written my first script. I am lost though on how to create a way to collect and plot my data. Using count was suggested, but even with that I am lost. Any help would be great. My script is below:
% Displays the number of seconds that have elapsed when the user presses
% only the 'k' and 'd' key.
KbName('UnifyKeyNames')
fprintf('Press the d key the left finger and the k key for the right. Each trial will last 60 seconds \n');
fprintf('Type the escape key to end the program.\n');
escapeKey = KbName('ESCAPE');
startSecs = GetSecs;
% Set up the timer.
durationInSeconds = 60 * 1;
numberOfSecondsRemaining = durationInSeconds;
RestrictKeysForKbCheck([75, 68, escapeKey])
ListenChar(2)
% Loop while there is time.
while numberOfSecondsRemaining > 0
numberOfSecondsElapsed = GetSecs - startSecs;
numberOfSecondsRemaining = durationInSeconds - numberOfSecondsElapsed;
[ keyIsDown, timeSecs, keyCode ] = KbCheck;
if keyIsDown;
fprintf('"%s" typed at time %.3f seconds\n',...
KbName(keyCode), timeSecs - startSecs);
if keyCode(escapeKey)
break;
end
% If the user holds down a key, KbCheck will report multiple events.
% To condense multiple 'keyDown' events into a single event, we wait until all keys have been released.
while KbCheck; end
end
end
답변 (1개)
Walter Roberson
2013년 1월 21일
0 개 추천
RestrictKeysForKbCheck and associated routines are not part of MATLAB; they are routines from psychtoolbox, which has its own forums.
In MATLAB, to check key presses and key releases, you create a figure, and then you use WindowKeyPressFcn callback and WindowKeyReleaseFcn callback.
카테고리
도움말 센터 및 File Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!