How can I save data to a csv file from a simulation in simulink without use the Matlab workspace?
143 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a simulation, and now I can write a csv file only if I use a Scope and save the data from that to csv file via Matlab workspace.
These are my tests:
csvwrite(’test.csv’,ScopeData5) dlmwrite(’test.csv’, ScopeData5, ’;’) dlmwrite(’test.txt’, ScopeData5, ’;’)
But if it's possible, I want to save my datas directly from my simulink model.
Thanks for any advice.
0 comentarios
Respuestas (5)
Jarrod Rivituso
el 23 de Mzo. de 2011
If you are just looking to have the .CSV file created by the end of the simulation, then you could use the model StopFcn to perform the save.
The steps would be...
1. Allow the model to write the data to the MATLAB workspace. For this, you can use the logged data from the Simulink scopes, as you have shown. Also, there are many other methods for capturing data from a simulation, such as logging signal data (right-click the signal and select Signal Properties) or saving root-level Outport data (this typically shows up in a yout variable in your workspace).
2. Add the csvwrite code to your model's StopFcn. To do this, select File -> Model Properties from the Simulink menu, then select the Callbacks tab, then put your csvwrite code in the StopFcn. The StopFcn gets called immediately after the simulation is over, so you can reference the logged MATLAB workspace variables from there.
Hope this helps!
0 comentarios
Kaustubha Govind
el 22 de Mzo. de 2011
There is no way to directly export simulation results to a CSV file, but you can use the "To File" block to log to disk as a MAT-file. (The MAT-file can be used directly or the data can be rewritten into a CSV later)
0 comentarios
Jarrod Rivituso
el 22 de Mzo. de 2011
Since you used the word "possible", I feel inclined to mention that you can write an S-function in C that could do this.
I know a guy that put an example of such a thing on the file exchange... :)
Of course, this is a more advanced approach.
0 comentarios
Szabolcs Pethe
el 22 de Mzo. de 2011
1 comentario
Jarrod Rivituso
el 23 de Mzo. de 2011
You cannot just erase the .mat extension and replace it with .csv. The .mat is a binary file format, very different from .csv.
However, you can easily load and save data from .mat files in MATLAB using the load and save functions. For example..
>> load('mydata.mat')
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!