How to save the last value of a simulation in a .mat ?
Afficher commentaires plus anciens
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
Réponses (1)
Sebastian Castro
le 8 Mar 2015
0 votes
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 commentaires
Aurelien Fremeaux
le 9 Mar 2015
Modifié(e) : Aurelien Fremeaux
le 9 Mar 2015
Sebastian Castro
le 9 Mar 2015
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
Catégories
En savoir plus sur Prepare Model Inputs and Outputs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!