Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 毫秒定时器_Matlab_Timer_Milliseconds - Fatal编程技术网

Matlab 毫秒定时器

Matlab 毫秒定时器,matlab,timer,milliseconds,Matlab,Timer,Milliseconds,我是一个业余的Matlab用户,正在尝试编写代码,以在1秒的时间跨度内每10毫秒运行一次特定的函数调用。我很难让某些东西在准确的时间内运行;我曾经尝试过使用Tic和Toc,但都是以秒为单位的(我需要毫秒精度)。下面是我一直在玩的一些非常基本的代码,用来尝试使用一个名为getvelocity的函数获取读数。任何帮助都将不胜感激,谢谢 function [ velocity ] = Vel() i=1; timerID=tic; while (toc(timerID) <=2); [

我是一个业余的Matlab用户,正在尝试编写代码,以在1秒的时间跨度内每10毫秒运行一次特定的函数调用。我很难让某些东西在准确的时间内运行;我曾经尝试过使用Tic和Toc,但都是以秒为单位的(我需要毫秒精度)。下面是我一直在玩的一些非常基本的代码,用来尝试使用一个名为getvelocity的函数获取读数。任何帮助都将不胜感激,谢谢

function [ velocity ] = Vel()
i=1;
timerID=tic;

while (toc(timerID) <=2);
    [v(i)]=vpx_GetTotalVelocity;
    disp (v(i));
    i=i+1;
end
velocity=mean(v);


end
函数[速度]=Vel()
i=1;
timerID=tic;

(toc(timerID)假设您拥有的函数足够快(不是一个简单的假设),您可以这样实现它:

tic
for t = 0.01:0.01:1 %If you want the first function call to start right away you can change this to 0:0.01:0.99
    while toc < t
    end
    t %Put your function call here.
end
tic
对于t=0.01:0.01:1%,如果要立即启动第一个函数调用,可以将其更改为0:0.01:0.99
而toc

请注意,0.01秒是10毫秒

如果您只想在函数调用之间等待10毫秒,请在函数调用之间使用
pause(0.01)
。@Lama精度并没有真正提到,但确实是Java的线程。睡眠应该更准确: