SimEvents - Setting Entity Attributes based on other entities
조회 수: 5(최근 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 2021년 5월 14일
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.
Learn more about MDES: https://www.mathworks.com/help/simevents/ref/matlabdiscreteeventsystem.html