Long time spent in simulink.c​ompiler.ge​tSimulatio​nOutput in postStepFcn that increases over time?

8 views (last 30 days)
I have a model I am trying to run with Simulink Compiler with live plotting using the postStepFcn. I notice that the pace of my simulation is slow. When using the profiler I see most of the time is spent in simulink.compiler.getSimulationOutput. I notice this function returns all the data for the simulation up to the current point. For a long running simulation this could be a lot of data and the time will increase as the simulation goes forward. Are there any alternatives?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 4 Apr 2025
Edited: MathWorks Support Team on 4 Apr 2025
Solution 1: PostStepFcn decimation. Consider using the decimation option of the postStepFcn. This can significantly improve performance by running the postStepFcn at a slower rate.
Solution 2: Use setExternalOutputFcn instead of simulink.compiler.getSimulationOutput
Can be used in conjunction with solution 1. Consider turning off all logging and instead using the setExternalOutputFcn to get the output of the simulation. This function will only return the output at the current step which can be faster for long simulations.
If you need to save some amount of historical data, consider implementing a circular buffer that is written to in the ExternalOutputFcn. Attached is an example of how to implement a circular buffer. In the example, a figure is used instead of App Designer but the concept translates to App Designer apps.

More Answers (0)

Categories

Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!