How to store output data from a simulink model to a text file
42 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I have a simulink model with several output signals in a bus. I'm monitoring one of the signals and I would like to store the time stamp when the signal is activated. This will only happen a few times during a 10 min long simulation with logged data. After the simulation has finished I would like to create a text-file containing the stored time stamps. I haven't worked with simulink for so long so I have no idea how to do this in an effective way! Thank you in advance!
Erik
0 commentaires
Réponses (3)
Fangjun Jiang
le 16 Sep 2011
There is no way available to write to a text file directly in Simulink. You can use the "To Workspace" block or "To File" (a .mat file) to store whatever data.
Then with those data, you can use save() in Command Window to save the data to a text file.
save File Data -ascii
2 commentaires
Fangjun Jiang
le 16 Sep 2011
Humh, that's a good question. When you say the signal is inactive, do you mean the signal is zero, or the signal is not even calculated.
If the signal is not even calculated, you must have those calculation inside a triggered or enabled system. You can try to put the "To Workspace" or "To File" block also inside that system to see how it works. I never used it that way before.
If the signal is zero, then I would say the zero signal still gives you valuable information. You should still record it. If you don't want to save all those zeros to a text file, you can do post-processing after the simulation and before writing to the text file. For example: Data below is your data, first column is time and second column is value:
Data=[1,0;2,1;3,0;4,0;5,0;6,1;7,0;8,0]
NewData=Data(Data(:,2)~=0,:)
Erik
le 19 Sep 2011
1 commentaire
Fangjun Jiang
le 19 Sep 2011
You are right. You need to use the "To Workspace" block and set the "save format" to be "structure with time". Then you can use save() in the Command Window to save the data to a .mat file.
Tung
le 26 Sep 2011
Hi Fangjun Jiang.
I think there is another way to write to a text file directly in Simulink that we add a function block with the code use the fprintf command. This is possible?
1 commentaire
Fangjun Jiang
le 26 Sep 2011
That's possible. You can try it and report it back. However, it will be inefficient and awkard. Simulation runs at every time step. You approach will require hard drive access at every time step, maybe even open and close the file at every time step.
Voir également
Catégories
En savoir plus sur Sources dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!