Share a state variable between 2 masked S-Function
3 views (last 30 days)
Show older comments
Giovanni Cignali on 22 Feb 2023
Answered: Mark McBroom on 16 Mar 2023
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 on 16 Mar 2023
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
More Answers (0)
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!