2012-02-09 137 views
6

我对tic函数有点困惑,但我不确定是否有更好的东西我想要做的。在psuedo-Matlab中:在Matlab中指定时间长度后断开循环

startTime = tic 

while(true) 

    #some_stochastic_process 

    if(now - startTime > RUNTIME) 
    break; 
    end 
end 

但随后调用tic将会破坏原始时间。有没有办法在不覆盖它的情况下访问tic的当前值?

回答

10

函数NOW返回一个序列日期编号(即编码的日期和时间)。另外

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 

,你可以简化你的循环,像这样:你应该改为与呼叫配对调用TICTOC进行秒表般的时机,像这样

while (toc(timerID) < RUNTIME) 

    %# Perform some process 

end 
+0

啊 - 我猜猜我对tic与toc的作用感到困惑。谢谢! – chimeracoder 2012-02-12 06:17:24