フィルターのクリア

Measure time until type a certain key

5 ビュー (過去 30 日間)
Shion
Shion 2023 年 3 月 27 日
回答済み: Walter Roberson 2023 年 3 月 27 日
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.

回答 (2 件)

Simon Chan
Simon Chan 2023 年 3 月 27 日
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

Walter Roberson
Walter Roberson 2023 年 3 月 27 日
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.

カテゴリ

Help Center および File ExchangeTiming 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!

Translated by