Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB tic-toc results in Minutes format

Tags:

timer

matlab

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!

like image 806
Maddy Avatar asked May 02 '11 19:05

Maddy


People also ask

How does Matlab calculate tic Toc?

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.

How do I show elapsed time in Matlab?

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.

Which of the following commands starts a Matlab stopwatch timer?

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 .


1 Answers

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));
like image 95
gnovice Avatar answered Sep 25 '22 01:09

gnovice