SimEvents - Setting Entity Attributes based on other entities

조회 수: 7 (최근 30일)
Marc Elpel
Marc Elpel 2021년 5월 14일
댓글: Marc Elpel 2021년 5월 14일
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
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.
  댓글 수: 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