我对 tic 函数有点困惑,但我不确定是否有更好的东西可以满足我的要求。在伪 Matlab 中:
startTime = tic
while(true)
#some_stochastic_process
if(now - startTime > RUNTIME)
break;
end
end
但是后续调用 tic 会破坏原始时间。有没有办法在不覆盖的情况下访问 tic 的当前值?
最佳答案
函数NOW返回一个日期序列号(即编码的日期和时间)。您应该改为将调用配对 TIC调用 TOC执行类似秒表的计时,如下所示:
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
或者,您可以像这样简化循环:
while (toc(timerID) < RUNTIME)
%# Perform some process
end
关于matlab - 在 Matlab 中指定的时间长度后中断循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9215911/