How to save the last value of a simulation in a .mat ?

Hello,
I'm having some troubles with something that looks easy : I would like to save the last value of a Simulink simulation to be stored in a .mat file without passing by a .m script. Kind of like a mix between the to-File block and the "Limit data point to last" option of the scopes, to Workspace, etc...
I know that the To-File block is able to log all the simulation but i really only need the last step !
Thank you in advance !
Aurelien

Answers (1)

Hello Aurelien,
Have you looked into saving a SimState? While the format might be different, it is a functionality we provide for saving data at the end of a simulation (presumably to use at the beginning of another simulation).
- Sebastian

2 Comments

Hello Sebastian,
This is the kind of functionality that I want, except that I plan on auto-generating code from the model and I'll stil need those saved datas ;). Moreover, I did not find how to save only specific datas (30 out of 100s). The only way I found for now is to use the StopFcn callback system (which is basically a m-file), and no way to do it with purely simulink blocks...
Aurélien
If you want this to work after auto code generation, I guess you could use the Configuration Parameters as shown below:
1. In the Data Import/Export pane, you can enable whatever type of logging that will get you your data. Also, check "Limit data points to last" and change the value to 1 such that you only get the last data point out.
2. In the Code Generation > Interface pane, check the "Enable MAT-File Logging" box. This should be available for both "grt.tlc" (Simulink Coder) and "ert.tlc" (Embedded Coder).
Note that the MAT-file logging works with the following blocks (from the documentation).
Enable MAT-file logging . When you select this option, the generated code saves to MAT-files simulation data specified in one of the following ways:
  • Configuration Parameters > Data Import/Export, Save to workspace subpane (see Data Import/Export Pane)
  • To Workspace blocks
  • To File blocks
  • Scope blocks with the Save data to workspace parameter enabled
- Sebastian

Sign in to comment.

Categories

Products

Asked:

on 5 Mar 2015

Community Treasure Hunt

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

Start Hunting!