How to measure the time an entity is in a system? (simulink)

When an entity is generated from the entity generator until it's termination from the entity terminator block it spends some time in the system. How can I calculate that time and is there a way at the end of the simulation to get an average time that an entity spends in the system?

 Accepted Answer

So I found out the solution myself and posting it in case anyone needs it. You add a simulink function (lets name it: start) inside the function delete everything it has and you add a digital clock block, which then you connect to an out1 block. You then create another simulink function(lets name it finish),(delete everything it has) with another digital clock block, an In1 block, a substract block and an out1 block. Connect the digital clock to the + of the substract block and the In1 to the - of the substract block and then the substract to the out1. Now connect the outport of the first function (start) to the input port of the other (finish). Last step: you need to call these functions, go to the entity creator --> event actions --> exit--> and add the name of the function, start(). Now go to the entity terminator --> event actions --> entry-> and add the name of the function, finish(). You can add a scope after the function finish. You can also add a mean block and then a display to calculate the average number of all the values you have obtained.

3 Comments

Hi John, one alternative that doesn't need the digital clock block consists in adding a property to the event type to store a timestamp, and managing it via event actions in generating and sink blocks. Try the attached example.

Sign in to comment.

More Answers (1)

To calculate the time an entity spends in the system and get the average time at the end of the simulation:
Add an "Event-Based Statistic" Block:
  • Connect it between the Entity Generator and the Entity Terminator blocks.
Configure the "Event-Based Statistic" Block:
  • Set the Statistics parameter to Time in Block.
  • This automatically measures how long each entity spends in the system.
Monitor the Average Time:
  • The block will provide the average time spent in the system at the end of the simulation.

1 Comment

there is no event based statistics block, at least at the academic version of 2024b

Sign in to comment.

Categories

Find more on Test Model Components in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 9 Feb 2025

Commented:

on 4 Mar 2025

Community Treasure Hunt

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

Start Hunting!