I need to write a code to record time stamps each time mouse is clicked. The following code works but only for 13 iteration or 13 presses. Is there a simpler way to do so?

3 Ansichten (letzte 30 Tage)
for i = 1:length('ButtonDownFcn')
waitforbuttonpress
tt(i) = now;
end

Antworten (1)

Walter Roberson
Walter Roberson am 28 Apr. 2016
length('ButtonDownFcn') asks for the length of the string 'ButtonDownFcn' which happens to be 13 characters.
How many presses would you like recorded, and how would you like the user to indicate that they want to stop clicking?
  8 Kommentare
Dushyant Dhundara
Dushyant Dhundara am 2 Mai 2016
Thanks for your input. I think the question I had posted originally is pretty clear what I am asking. I do not require any of the functionalities you have listed. Anyways thanks for the help
Walter Roberson
Walter Roberson am 2 Mai 2016
S.hFig = figure('menu','none',...
'pos',[400 400 320 50]);
S.th = uicontrol('Style','text','Position',[10 10 300 30],...
'String','Hit Space Bar to record Time Stamp');
timestamp = [];
set(S.hFig,'KeyPressFcn', @(~,~) assignin('base', 'timestamp(end+1)', now));
Caution: this will only work as a script, not within a function.
There is no specific way to stop: clicks will be recorded as long as the user cares to make them. You can access the timestamp variable any time after it is initialized. The user is not given any method to indicate that they want to stop, or that any further action should be taken, because that is a feature you have indicated you do not require.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by