Why are the states not executing properly in the Simulink function?

I am using three subsystems: one contains a Stateflow chart with states, and the other two contain Simulink functions, each with its own Stateflow block. I am using nested Simulink functions and calling them through Stateflow. However, the states are not executing properly inside the Simulink functions. Can anyone help me understand why this is happening and what might be causing it?
I have attached some snapshots and the .slx file for your reference and clarification.

Answers (1)

Hi Kathir,
In the provided model, the execution appears inconsistent due to a mismatch between the desired execution time and the execution order of the blocks. To ensure proper execution, two issues need to be addressed:
  1. The first issue can be resolved by disabling the 'Execute (enter) chart at initialization' parameter for both the 'def_Chart' and 'Fun_Caller' charts. This prevents them from executing at initialization.
  2. The second issue arises when the function named 'Call' is invoked. It executes only one state in 'def_Chart' before execution returns to the 'Fun_Caller' chart, causing a discrepancy. To address this, enable the 'Enable super step semantics' parameter for the 'def_Chart' chart.
These parameters can be found in the advanced section of the property inspector after selecting the respective charts. The property inspector is accessible from the design section of the modeling tab in the toolstrip.
For further reference, the resolved file 'resolved.slx' is attached. Please also refer to the following documentation on Stateflow chart properties: https://www.mathworks.com/help/releases/R2024a/stateflow/ug/specifying-chart-properties.html#:~:text=Stateflow%20API.-,Stateflow%20Chart%20Properties,-You%20can%20set

3 Comments

Thank you for your response.
I followed your instructions based on the input, but it runs once and doesn’t execute on subsequent calls. I went through the provided link, but I couldn’t find a solution there.
I’ve attached my model (.slx) file and a snapshot of it for your reference. Could you please take a look and assist me further?
Please excuse the late response, I was away from the community for a while.
In the attached model, function 'Call' is executed only once and then the execution moves to state 'Re_Init'. The execution is not able to exit the 'Re_Init' state and come back to 'Init' as the defined condition 'prev~=in' is never met. Try changing the condition as desired.
I would also recommend you to go through the 'Stateflow Onramp' to gain better understanding of Stateflow. Link to the Onramp: https://matlabacademy.mathworks.com/details/stateflow-onramp/stateflow

Sign in to comment.

Categories

Products

Release

R2024a

Asked:

on 3 Mar 2025

Commented:

on 6 May 2025

Community Treasure Hunt

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

Start Hunting!