SimEvents - Setting Entity Attributes based on other entities

6 次查看(过去 30 天)
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?

采纳的回答

Abdolkarim Mohammadi
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 个评论
Marc Elpel
Marc Elpel 2021-5-14
Thanks! I'm going to implement via the MDES as it looks like that will help in other areas of my code as well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by