How can I get the wall-clock time during my simulation, once an entity reaches a certain block?
7 次查看(过去 30 天)
显示 更早的评论
I'm trying to get the real-time spent from when an entity leaves one block, and until it reaches another. I've tried using functions like tic and toc to create a stopwatch, but nothing is working.
For each entity that leaves the entity generator, I'd like it to have its own start time, and then each entity would have its own stop time when it reaches its destination block. So I want an array of start and stop times for each entity, all in wall-clock time.
Any help would be much appreciated.
0 个评论
回答(1 个)
Joshua
2017-7-8
Is this what you are looking for? It gives you the current time in seconds from the start of the day. You could modify it to suit the format you want, but using the clock function is key.
n=30;
times=zeros(n,2);
x=linspace(1,10,10000);
y=cos(x.^2);
format long
for i=1:n
c=clock;
times(i,1)=c(4)*3600+c(5)*60+c(6);
close all
plot(x,y)
c=clock;
times(i,2)=c(4)*3600+c(5)*60+c(6);
end
Note that I made a random loop plot something just to emulate a process taking up time.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete-Event Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!