필터 지우기
필터 지우기

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