Write output of To File block to MAT file incrementally during simulation of generated executable

1 view (last 30 days)
I am generating an executable from my Simulink model in order to speed up execution. I output the data using a To File block. However, when I run the generated executable, I cannot access the data from the To File block until the very end of simulation. This is undesirable, since I am running a very long simulation and would like to see the intermediate results. Additionally, if the simulation is terminated early, all the data is lost. Is there a way to access the results while the executable is running? This is possible during Normal mode simulation by pausing the simulation.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Apr 2019
When running a generated executable, the data written by the "To File" block cannot be accessed until the end of simulation because the file is open for writing. A simple workaround is to create a custom S-function that writes the desired outputs to a text file during simulation. To do so, you can use the "S-function Builder" block. I have attached a simple model containing an S-function that buffers data and writes to a file every "x" time steps, where "x" is specified as a parameter of the S-function. This is only a simple example, and you can modify it as fit for your model.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!