How can I save data to a csv file from a simulation in simulink without use the Matlab workspace?
143 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(5 个)
Jarrod Rivituso
2011-3-23
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 个评论
Kaustubha Govind
2011-3-22
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 个评论
Jarrod Rivituso
2011-3-22
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 个评论
Szabolcs Pethe
2011-3-22
1 个评论
Jarrod Rivituso
2011-3-23
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')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!