Why am I getting negative seconds when subtracting clock times?
4 views (last 30 days)
Show older comments
I'm trying to create a function that subtracts the start time from the end time of a trial to calculate the trial duration:
trialstart{n_trial} = clock;
trialend{n_trial} = clock;
trialduration{n_trial} = trialend{n_trial}-trialstart{n_trial};
For many trials the code works fine, with trialduration results like the following:
[0,0,0,0,0,7.3425]
However, I notice that when a trial extends from the end of one clock minute into the start of the next clock minute, the trialduration function returns a positive minutes value and a negative seconds value, like this:
[0,0,0,0,1,-53.4844]
This is, of course, not wrong...but I would much prefer to just see a positive number of seconds each time. Any suggestions would be appreciated. Thanks in advance.
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Clocks and Timers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!