Matlab代码5毫秒定时器
有谁能告诉我如何在matlab中编写5毫秒的定时器代码吗 %%分解为一组40字节的数据包 %当时间Matlab代码5毫秒定时器,matlab,Matlab,有谁能告诉我如何在matlab中编写5毫秒的定时器代码吗 %%分解为一组40字节的数据包 %当时间0 对于n=1:长度(总字节数) %n=通过“总字节数”marix的计数器 数据包=[];%40字节矩阵(打包阶段) %检查每个TalkSport时段的字节数是否小于或>40字节,以便开始打包 if(总字节数)(n)以提高精度 java.lang.Thread.sleep(5); 关于更多信息,请参阅更多信息,而不是tic toc。tic和toc受到了不好的评价,所以我将发布这篇文章 我尝试了以
%while(Total_Connection_Time-Running_Time)>0
for n=1:length(total_number_of_bytes)
% n=counter to go through "total_number_of_bytes" marix
packets=[]; % 40-bytes matrix (packetization phase)
% checking whether number of bytes at each talkspurt period is < or > 40 bytes in order to start packetization
if (total_number_of_bytes(n)<=40)
k=40-total_number_of_bytes(n); % calculating how many remaining bytes we need to complete a 40 bytes packet
packets=[packets,total_number_of_bytes(n)+k];
total_number_of_bytes(n)=40; %new bytes matrix after packetization (adding bytes from next talkspurt to get total of 40 bytes)
total_number_of_bytes(n+1)= total_number_of_bytes(n+1)-k; % bytes are taken from the next talkspurt period in order to get a 40 byte packet
if total_number_of_bytes(n+1)<0
for i=1:length(total_number_of_bytes) % looping through the array starting total_number_of_bytes(n+1)
total_number_of_bytes(n+1)=total_number_of_bytes(n+1)+total_number_of_bytes(n+1+i)
total_number_of_bytes(n+1+i)=0;
packets=[total_number_of_bytes]
end
end
end
if(total_number_of_bytes(n)>40)
m=total_number_of_bytes(n)-40; % cz we need 40 bytes packets
packets=[packets,total_number_of_bytes -40];
total_number_of_bytes(n)=40;
total_number_of_bytes(n+1)= total_number_of_bytes(n+1)+m; % The remaining bytes are added to the next talkspurt period bytes
packets=[total_number_of_bytes]
end
%while(总连接时间运行时间)>0
对于n=1:长度(总字节数)
%n=通过“总字节数”marix的计数器
数据包=[];%40字节矩阵(打包阶段)
%检查每个TalkSport时段的字节数是否小于或>40字节,以便开始打包
if(总字节数)(n)以提高精度
java.lang.Thread.sleep(5);
关于更多信息,请参阅更多信息,而不是tic toc。tic和toc受到了不好的评价,所以我将发布这篇文章
我尝试了以下方法:
tic
count = 0;
while toc<0.005
a=randn(10);
count = count+1;
end
toc
tic
计数=0;
当toc时,您是否只想写入一个5ms块?如果是这样,请在开始处放置一个tic
,并在每个循环的开始处检查toc的值。如果您需要以精确的5ms间隔重复toc,则最好的方法是使用带回调的计时器功能。使用t时,您将无法获得接近毫秒的精度ic
和toc
,定时器
,或一般的MATLAB。@Dustinvor我确信标准偏差可能很小,但我不明白这有什么关系。你已经运行了很多次tic/toc,并要求他们在报告的时间非常接近0.005时停止。当然,你得到的答案都非常接近0.005-你设计的东西就是为了实现这一点。然而,tic
和toc
报告的时间不精确到毫秒以内。@SamRoberts,我没有意识到。你能提供一个参考吗?@dustenvor我很抱歉-请忽略我以前的评论。我不知道这一点,但在R2008年btic
和toc
被完全重新实现,精确度大大提高,从以前的大量毫秒提高到现在的大约一微秒。非常好。