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!