How to Read and Reuse FMU Internal Variables in MATLAB/Simulink?

7 views (last 30 days)
Hey everyone,
I'm working with FMUs (Functional Mock-up Units) in MATLAB/Simulink and I'm trying to figure out how to read systematically the internal variables at the end of a simulation and reuse them for another run. This would really speed up the startup phase of our simulations.
In my previous job, I had a script that did this – it accessed and stored the internal variables at steady state and then reused them at the start of a new simulation. Unfortunately, I don't have that script anymore. MathWorks support had provided the details of the API back then, but I can't seem to find it now.
Does anyone know:
  • Which API or functions are available to read FMU internal variables at the end of a simulation?
  • How to store these variables and reuse them in subsequent simulations?
  • Any example scripts or documentation that could help with this?
Thanks a lot for your help!

Answers (1)

Epsilon
Epsilon on 15 May 2025
Hi gmos,
The internal states of the FMU can be captured by Simulink if the option for "Enable FMUState capability" is selected during the export of the FMU. This option is available in the advanced section of the export dialogue box, or as an input parameter (EnableFMUState, on) for the exportToFMU function.
The get_param function can then be used to capture the internal states of the FMU during iterative simulation. Enabling "Fast Restart" in the Simulate section of the toolstrip can also help speed up subsequent iterations. This example might be helpful for your scenario: https://www.mathworks.com/help/slcompiler/ug/FMUState-for-ModelStates-FastRestart-Stepping.html
The internal variables for the model can alternatively be stored and exported in the FMU, but they are limited to what is logged in the original model and do not capture the full FMU state. The documentation on exporting FMUs with internal variables can be found here: https://www.mathworks.com/help/slcompiler/ug/export-fmu-with-internal-var.html
Hope it helps!

Categories

Find more on RF Blockset Models for Transceivers in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!