How can I save all of the data from a simulation running in external mode to one file?

40 views (last 30 days)
I am using a Simulink model to control a small robot. The model is compiled using the Real-Time Windows Target (ERT), and runs in external mode for 100 seconds. I have disabled the "limit data points to last" setting in the scope as well as in the configuration parameters, but the scope will only save to the workspace and display the last 10 seconds of simulation time. Additionally, the "ToFile" block is not supported by the real-time windows target. How can I save all of the data from my simulation? Is there a different block I can use?
Thank you for your help, I have spent a lot of time trying to solve this problem already.

Accepted Answer

Siddharth Mohan
Siddharth Mohan on 15 Mar 2016
Hi Matt,
We've heard this request from customers before and we have it in our plans to address it sometime in the future. For now, you can save the complete simulation data using the 'External Mode Control Panel'. You can do it in two different ways.
1) Increase the External mode trigger duration.
If you have a finite running simulation, you can change the External mode trigger duration to log more data. From your model, go to Code->External Mode Control Panel-> Signal & triggering -> Duration. Set this to a number that might be enough for you to capture the simulation data. Please note that some targets might limit you to have a specific trigger duration.
2) Saving simulation data to MAT files
You can also save simulation data to MAT file(s). The number of MAT files generated will depend on the 'External mode trigger duration'. For example: If the trigger duration is set to 100 and the complete simulation generates 200 data points, you will get two MAT files. The first will have data stored in a variable from T1 -> T100 and the second will have data from T101 -> T200. You can follow the steps below to try this out.
a) Code -> External Mode Control Panel -> Data Archiving
b) Check the 'Enable archiving' box.
c) In the 'Directory' edit box, specify a directory where you'd like to save the MAT file(s)
d) In the 'File' edit box, enter a name for your MAT file.
Let me know if you have other questions!
HASHIM MM on 16 Jun 2021
I too faced an issue with the logging. I tried the solution provided to save to mat files. For me only the first matfile is having data. The other mat files created by the trigger are all empty. When I disconnect and connect again , the first mat file after disconnect will contain the data and the rest of them generated with the triggers are all empty. Has someone faced this issue?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!