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

7 views (last 30 days)
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.

Answers (1)

Joshua
Joshua on 8 Jul 2017
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 Comment
Andrew Natarian
Andrew Natarian on 10 Jul 2017
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.

Sign in to comment.

Categories

Find more on Discrete-Event Simulation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!