Share a state variable between 2 masked S-Function
조회 수: 3(최근 30일)
표시 이전 댓글
Giovanni Cignali 2023년 2월 22일
답변: Mark McBroom 2023년 3월 16일
We are having some issues when trying to share a state variable between 2 masked S-Function. In the picture below, as you can see there is the same S-Function called 2 times behind a mask. In this example, the S-Function is a SR Flip Flop:
The green block is supposed to set the State variable (passed as a Mask Parameter) of the Flip Flop to a specific value (true or false) such that the orange block can use it during the execution.
Since the 2 inputs of the orange block are ‘false’ the output of the block should be the previous state. In this case, if the state is shared between the 2 subsystems, the 2 signals inputs to the scope should be the same signal. However, the orange block and the green block never share the same state even if the 2 mask parameters point to the same data dictionary variable (Below the Mask we have the state name passed to the Mask). In the picture below you will find both the scope representing the 2 signals.
We have properly passed the state to the S-function as a parameter inside the mask and the state is correctly updated at each step inside the S function, the issue is that the data dictionary variable is never updated by the S-function, only the variable inside the simstruct gets updated during the execution of the S-function.
Mark McBroom 2023년 3월 16일
It is not possible to have an S-Function update the value of data dictionary value. See this link for approaches you can take to share data between s-functions. https://stackoverflow.com/questions/53155193/share-data-between-multiple-c-mex-s-functions
Find more on Configure C/C++ S-Function Features in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!