SimEvents - Setting Entity Attributes based on other entities

6 vues (au cours des 30 derniers jours)
Marc Elpel
Marc Elpel le 14 Mai 2021
Commenté : Marc Elpel le 14 Mai 2021
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?

Réponse acceptée

Abdolkarim Mohammadi
Abdolkarim Mohammadi le 14 Mai 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 commentaire
Marc Elpel
Marc Elpel le 14 Mai 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete-Event Simulation dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by