Share a state variable between 2 masked S-Function

4 次查看(过去 30 天)
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
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
THanks.
Mark.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Block and Blockset Authoring 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by