how to prioritize the out port execution order?

3 views (last 30 days)
ED
ED on 21 Mar 2025
Answered: Anushka on 24 Mar 2025
This is the example of the model, I want to update the output after the Filter 1 and filter 2. But the code generated is against the will even the execution orders were changed.
So, how to set the configuration to achieve updating all calculation before updating outport?

Answers (1)

Anushka
Anushka on 24 Mar 2025
Hi @ED,
To ensure that the Outport execution occurs after all filter calculation, you should:
  1. Wrap each filter block and output block in ‘nonreusable atomic subsystems’.
  2. Enable ‘Late Inline’ to prevent Simulink Coder optimizations from changing the execution order.
The following steps resolved the issue for me:
  1. Group the Filter and Outport Blocks:
  • Select Filter 1 and Filter 2, then right-click → Create Subsystem.
  • Do the same for the Outport block.
  • You should now have Filter_Subsystem and Outport_Subsystem.
2. Set the Subsystems as Nonreusable:
  • Double-click each subsystem → Block Parameters.
  • In the Code Generation tab: Function packaging → Nonreusable function
  • InlineApply ‘Late Inline’ via MATLAB scripting in the command line:
set_param(model_name/subsystem_name, 'RTWSystemCode', 'Inline');
3. Adjust the Execution Order:
  • Go to Model Configuration ParametersSimulation Order.
  • Set the execution order so that: Filter_Subsystem executes before Outport_Subsystem.
  • This guarantees all filtering calculations are completed before updating the Outport.
You can refer to the following documentation to get details about how to create a subsystem: https://www.mathworks.com/help/simulink/ug/creating-subsystems.html
Hope this helps!

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!