matlab - 在 Matlab 中指定的时间长度后中断循环

标签 matlab timer

我对 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/

相关文章:

MATLAB 示例失败

matlab - R 中 matlab 的 pcolor 的等价物是什么?

ios - 在间隔不为 1 的 NSTimer 上显示每秒获取更新

Matlab:如何将元胞数组中的元胞切割为相同的长度

c++ - 如何在 C++ 中编写 MATLAB fix(X) 函数?

function - 存在两个时如何选择特定的 .m 函数?

vbscript - 如何制作 VBScript 定时器

xamarin - 如何在完成之前取消计时器

swift - 设置 WatchKit 计时器的倒计时间隔

java - 如何使用 javax swing 计时器的整数数组来改变速度