Toc returns loop time instead of total script time
38 visualizzazioni (ultimi 30 giorni)
I have a script with a large loop nested inside another loop, and i would like to time the progress of the loop, using the tic/toc commands.
The code is like this:
--some code and small loops--
disp(['Iteration: ' num2str((i-1)*lengthj+j) ' of ' num2str(lengthi*lengthj)]);
however, when I run the code, toc seems to display the time since last toc, instead of the time since tic. The problem is not exclusive to this piece of code, I have noticed it before with other scripts.
Any thoughts or experience with this?
pfb il 27 Apr 2015
Modificato: pfb il 27 Apr 2015
I've tried this
on both R2012b and R2014b and the output is what I expect: after each toc 2 seconds are passed
Elapsed time is 2.000970 seconds.
Elapsed time is 4.002267 seconds.
Elapsed time is 22.011765 seconds.
Philip Borghesani il 29 Apr 2015
Modificato: Philip Borghesani il 29 Apr 2015
Clear all and clc will not clear tic time.
There must be another call to tic. For this reason I recommend always using the t0=tic; t=toc(t0) form of these functions.
To find other calls to tic try dbstop in tic or write your own version of tic that checks for other uses.
A foolproof way to find the call to tic with no output is to fix your outer loop to call t0=tic and place this tic.m in your current directory: