How can I get the wall-clock time during my simulation, once an entity reaches a certain block?

6 次查看(过去 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.

回答(1 个)

Joshua
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.
  1 个评论
Andrew Natarian
Andrew Natarian 2017-7-10
I'm looking to get the clock time it takes an entity to leave one block, and enter another, in my Simulink model. So how would I put this code into a block as an Event Action?
If I try to use clock in a Simulink block I get, "Function 'clock' is not supported for code generation. Consider adding coder.extrinsic('clock') at the top of the function to bypass code generation". I got the same error with the tic and toc functions.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by