I am using tic-toc function in my Matlab project as many places. The output time can be 331.5264 or 1234.754 seconds
, etc. Can I output this is minutes format? For eg. 5 minutes and 30.6 seconds
? Thanks!
tic works with the toc function to measure elapsed time. The tic function records the current time, and the toc function uses the recorded value to calculate the elapsed time. timerVal = tic stores the current time in timerVal so that you can pass it explicitly to the toc function.
toc( timerVal ) displays the elapsed time since the call to the tic function corresponding to timerVal . elapsedTime = toc returns the elapsed time since the most recent call to the tic function.
tic, toc (MATLAB Functions) tic starts a stopwatch timer. toc prints the elapsed time since tic was used. t = toc returns the elapsed time in t .
All you have to do is capture the output from toc
(instead of letting it display its default output), then create an output yourself using the functions fprintf
, floor
, and rem
:
tStart = tic;
% Do some things...
tEnd = toc(tStart);
fprintf('%d minutes and %f seconds\n', floor(tEnd/60), rem(tEnd,60));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With