2012-02-09 22 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