How to store output data from a simulink model to a text file
조회 수: 47 (최근 30일)
이전 댓글 표시
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
답변 (3개)
Fangjun Jiang
2011년 9월 16일
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
Fangjun Jiang
2011년 9월 16일
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
2011년 9월 19일
댓글 수: 1
Fangjun Jiang
2011년 9월 19일
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
2011년 9월 26일
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
Fangjun Jiang
2011년 9월 26일
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.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!