I'm a bit confused by the tic function, but I'm not sure if there's something better for what I'm trying to do. In psuedo-Matlab:
startTime = tic
while(true)
#some_stochastic_process
if(now - startTime > RUNTIME)
break;
end
end
But subsequent calls to tic will clobber the original time. Is there a way to access the current value of tic without overwriting it?
The break statement exits a for or while loop completely. To skip the rest of the instructions in the loop and begin the next iteration, use a continue statement. break is not defined outside a for or while loop. To exit a function, use return .
when an loop is running ctrl + c (just ctrl and c ) will exit any loop..
This functionality is not availble when using the function BREAK. BREAK will only break out of the loop in which it was called. As a workaround, you can use a flag variable along with BREAK to break out of nested loops.
Alternatively, you can press the F12 key to set a breakpoint at the current line. If you attempt to set a breakpoint at a line that is not executable, such as a comment or a blank line, MATLAB sets it at the next executable line.
The function NOW returns a serial date number (i.e. an encoded date and time). You should instead be pairing the call to TIC with a call to TOC to perform stopwatch-like timing, like so:
timerID = tic; %# Start a clock and return the timer ID
while true
%# Perform some process
if(toc(timerID) > RUNTIME) %# Get the elapsed time for the timer
break;
end
end
Alternatively, you could simplify your loop like so:
while (toc(timerID) < RUNTIME)
%# Perform some process
end
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