You are encountering unexpected behavior because Stateflow does not recognize the pattern you added under the 'during' action; instead, it categorizes it under the 'entry' action. Consequently, the 'if-else' pattern executes before the statements in the 'during' action.
To better understand the execution flow, I included 'print' statements. Refer to the state below:
The output after executing is attached below:
From the output, it's evident that 'In Pattern' is printed before 'In During', indicating that the execution goes to the pattern blocks instead of 'during' action.
I understand you replaced 'if-else' statements with a pattern because the C-Action Language doesn't support conditional control statements. This behavior is expected even when using MATLAB as the Action Language with such patterns. You can leverage the Graphical Functions and call the function within the 'during' action. Refer to the below attached example:
The output below gives expected result:
For more information on implementing Graphical Functions, you may refer to the following documentation:
I hope this resolves your query.