SimEvents - Setting Entity Attributes based on other entities

7 visualizaciones (últimos 30 días)
My app needs to assign an entity attribute in Entity1 based on an attribute value in Entity 2.
I can use a function GetAttribute to get a specific attribute from Entity 1, but how do I assign that to an attribute in entity 2?

Respuesta aceptada

Abdolkarim Mohammadi
Abdolkarim Mohammadi el 14 de Mayo de 2021
You can implement this in two ways. The first approach is easier, and can be implemented via existing SimEvents blocks, but can only be used in special cases of time-driven entity generation. The second approach requires learning how to work with a new block, but has the superiority to be used in event-driven entity generation.
1. Via Simulink function or Data store. When Entity1 enters the prespecified block, set its attribute using a Simulink function or a Data store. When Entity2 arrives in the prespecified block, it can retrieve the value of the attribute. The limitation of this approach is that no other entity should enter between Entity1 and Entity2. In other words, Entity1 and Entity2 must enter the blocks sequentially.
2. Via MATLAB Discrete-Event System (MDES). MDES is very powerful and flexible. I suggest learning it to use it in this projects and your future projects. Standard SimEvents blocks only have one storage, and those storages cannot communicate with each other. If you need to communicate between storages, you need to use MDES. Using MDES, you can create an Entity1Entry event action and set the attribute to a private property of the MDES. Then you can generate Entity2 using eventgenerate event. Then in the Entity2Generate event action you can query the attribute value and set it.
  1 comentario
Marc Elpel
Marc Elpel el 14 de Mayo de 2021
Thanks! I'm going to implement via the MDES as it looks like that will help in other areas of my code as well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete-Event Simulation en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by