how to implement matlab count
Afficher commentaires plus anciens
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
Réponses (1)
Walter Roberson
le 21 Jan 2013
0 votes
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.
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!