필터 지우기
필터 지우기

How to store output data from a simulink model to a text file

조회 수: 43 (최근 30일)
Erik
Erik 2011년 9월 16일
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

답변 (3개)

Fangjun Jiang
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
Erik
Erik 2011년 9월 16일
Thank you for the answer! Is there some easy way to only store data to a mat-file when the signal is active?, in order to reduce the size of the mat-file for long simulations.
Fangjun Jiang
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
Erik 2011년 9월 19일
Thank you for your answer! Sorry I didn't expalin to well! The signal is either zero or a square wave with value 1. I stored all values during the simulation and filtered the data after and it works fine!
I have another question you might be able to answer. One other signal I would like to monitor is boolean. What I would like to do is to save the current time when this signal is true. I don't think it's possible to use save to file with save format Array.
  댓글 수: 1
Fangjun Jiang
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
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
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by