Execution order of blcks

1 view (last 30 days)
Pranav
Pranav on 5 May 2025
Answered: Anushka on 9 May 2025
How can I control the execution order of blocks so that certain computations are completed before the Outport updates, especially when the generated code doesn’t follow the visual or manual block order set in the model?

Accepted Answer

Anushka
Anushka on 9 May 2025
To guarantee that the Outport executes after all filter calculation in code generation, you should take extra steps beyond setting “First”/”Last” execution order because code generation optimization may otherwise reorder blocks. You can follow the steps to ensure correct execution order:
1. Group your blocks into a subsystem and place the Outport block in its own subsystem.
2. For each subsystem:
  1. Open Block Parameter -> Code Generation tab
  2. Set Function packaging to Nonreusable function.
  3. To prevent code generation optimizations reordering these operations, mark the subsystem for late inling using the following MATLAB command:
set_param(model_name/subsystem_name, 'RTWSystemCode', 'Inline');
3. In the Simulink model, ensure that your blocks execute before Outport subsystem. You can do this by :
  1. Adjust your block priorities.
  2. Using Model Configuration Parameter -> Simulink Order
Hope this helps!

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 5 May 2025
You can set the block priority number. There are limitations. See

Categories

Find more on Interactive Model Editing 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!