Clear Filters
Clear Filters

Share a state variable between 2 masked S-Function

6 views (last 30 days)
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.

Accepted Answer

Mark McBroom
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
THanks.
Mark.

More Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!