帮助‘停顿’说
PAUSE(n) pauses for n seconds before continuing, where n can also be a
fraction. The resolution of the clock is platform specific. Fractional
pauses of 0.01 seconds should be supported on most platforms. 但在我的例子中,暂停(0.01)根本不起任何作用(停顿,暂停(N)与整数n工作)
在matlab中有什么方法可以产生毫秒级延迟(50 ms,100 ~ 500 ms)?
Matlab版本是
MATLAB Version 7.9.0.529 (R2009b) Windows 10 64位家庭版上的64位
发布于 2020-07-28 06:58:10
我有两种选择。让我们称它们为循环选项和本机选项。第一种方法是使用while循环来检查您期望的等待时间是否已经达到。你可以用MATLAB的秒表计时器tic和toc来完成这个任务。这是正常时间(不是CPU时间).当您正在编写一个循环时,它以最大的速度运行,您可能会遇到较高的CPU使用率,但如果只运行几毫秒,这应该是可以的。
%% looping
% desired time to wait
dt_des = 0.001; % 1 ms
% initialize clock
t_st = tic;
% looping
while toc(t_st) < dt_des
end
% read clock
toc(t_st)本机选项是使用pause (确保已使用pause('on')启用过一次)。我从您的问题中假设,这并不总是有效的--但是,它在我的系统上是这样的(R2019b,windows 10)。
%% use pause()
tic
pause(0.001)
toc两者的结果如下
Elapsed time is 0.001055 seconds.
Elapsed time is 0.001197 seconds.这不是太准确,但你可能会得到更好的结果,如果你调整你的电脑上的数字。
发布于 2020-07-28 07:08:05
https://stackoverflow.com/questions/63127994
复制相似问题