Measure time until type a certain key
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am currently considering recording the time that an animal in a video performs a particular action.
I have tried using the tic toc function and the if syntax to "record the time until a specific key is pressed in the matrix when a specific key is pressed (e.g., Enter)," but it does not work.
I would appreciate any code suggestions you may have.
0 Kommentare
Antworten (2)
Simon Chan
am 27 Mär. 2023
Attached is a small program that you may try to see whether it is suitable for your purpose of not.
It will open an empty figure and trigger the callback when any key is pressed.
When the 'Enter' key is detected, it will log the current time and the time difference between 2 instances will be calculated.
function recordAction(src,event)
f = figure('WindowKeyPressFcn',@keyPress);
record = []; % Variable store the instance when 'Enter' key is pressed
%%
function keyPress(src,event)
key = get(src,'CurrentKey'); % Get the key pressed
if(strcmp (key , 'return'))
record = [record;datetime('now','Format','dd-MMM-yyyy HH:mm:ss.SSS')];
Delta =diff(record); % Calculate time difference
Delta.Format = 'hh:mm:ss.SSS'; % Set the duration format
display(Delta) % Display the time difference
end
end
end
0 Kommentare
Walter Roberson
am 27 Mär. 2023
The time that something in video happens should be derived from the frame number and the frame rate that the action is detected on. If you are using a video reader you can typically inquire about the time property of the video -- which is usually the best thing to do as the time property properly takes into account variable frame rates.
If you want to determine the time that a human performs an action, then you should be considering looking at the third party Psychtoolbox http://psychtoolbox.org/ which offers tools for measuring reaction times for psychometric experiments.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!