Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Record and export numeric outputs to csv file

0 votes
89 views
Hi all I am doing a simulation on microgrids and I would like to export parameters like solar(Power), wind(Power), user load(Power), battery state of charge etc into a csv file for data analysis purposes like energy forecasting. I have tried using the "ToFile" function however I have encountered the following issues that I could not solve:

1. The CSV file gets overwritten everytime i run my simulation.

2. Some of the parameters have the wrong display names on the first column of the file

3. I am unable to get the computer's time and use them in the CSV file as timestamps to show when the data was recorded.

 

What are the possible solutions I can try? Can I try and do a c-script or state machine? Any advise would be appreciated! Thanks everyone
asked Mar 4 by Edmund (14 points)

1 Answer

0 votes
Please see my responses below.  Feel free to attach any example models that may clarify some of your questions, especially on point #2.

> 1. The CSV file gets overwritten everytime i run my simulation.

This is the default behavior. If one is doing multiple simulation runs, typically one would use a simulation script.  Then in the simulation script you could modify the ToFile name according to the test conditions or test number.  The Filename can be an arbitrary octave string when the Filename parameter is set to Evaluate.

If the goal is to manually tweak something in the model, re-run the simulation, and then save the results, one option is to construct the file name in the model initialization commands based upon the relevant settings.  Another approach would be to have the filename be a function of run-time or run-number. I personally find this less attractive as the user will have to write down which run # corresponds to which conditions. This can also generate many large files.

One can construct a string denoting the time at the start of simulation using octave. One would set this as the Filename and set the filename parameter to evaluate.

timeStr = strftime ("%y_%m_%d_%r", localtime (time ()));

csvName = ['SimRun',timeStr]

> 2. Some of the parameters have the wrong display names on the first column of the file

The CSV file names come from the name of the upstream component. You can modify the component name to get the desired description in the header.

> 3. I am unable to get the computer's time and use them in the CSV file as timestamps to show when the data was recorded.

Is there a reason to have the local time reported at every simulation step?  The only case I've heard this in the past is as a proxy to find where the simulation may become slow.  Does modifying the filename, noted above, address this concern?
answered Mar 6 by Bryan Lieblick (1,887 points)
edited Mar 7 by Bryan Lieblick
...