How do you store output data in a text file during simulation ?

4 views (last 30 days)
Our project requires a non-corruptible form of data storage in the sense that even if there is a power failure or an emergency shutdown, we want to be able to retrieve previously logged data and resume operations. We currently log data around every 5 seconds and have been making use of the To File Block in Simulink. I want to know if there is a way to store this logged data in a text based format instead, in Simulink.
If not, is there a way to ensure that the .mat file doesn't get corrupted if the file doesn't close properly ? We ran an experiment where the computer was hard reset (forced shutdown) and tried to open the .mat file. This gave us junk values (the data was constant at -209.8 for all the logging intervals and only logged arbitrarily and at non-specified time stamps).
I would appreciate if someone could shed some light on this issue.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 2 Jul 2013
You might need to write a custom block (perhaps using a MATLAB S-function) to do the logging to a text file for you. I don't think the "To File" block closes the MAT-file until simulation is stopped - in fact, I wouldn't imagine that it writes to the file immediately either. My guess is that the block has an internal buffer that it writes to, that is then written to file only when the buffer gets full.

Products

Community Treasure Hunt

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

Start Hunting!