毫秒计时器matlab

时间:2013-07-02 04:55:35

标签: matlab timer milliseconds

我是一位业余的Matlab用户,他尝试编写代码,每隔10秒运行一次特定的函数调用,持续时间为1秒。我无法在确切的时间内尝试运行某些东西;我曾尝试使用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

上面的代码运行了两秒钟;但是,我希望以ms精度运行。

1 个答案:

答案 0 :(得分:0)

假设你拥有的功能足够快(不是一个微不足道的假设)你可以像这样实现它:

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

注意0.01秒是10毫秒

相关问题