How to make a continous csv export in Simulink

조회 수: 29 (최근 30일)
Damien Pecher
Damien Pecher 2023년 2월 17일
댓글: Damien Pecher 2023년 2월 21일
Hi,
I have a Simulink model that runs for an infinite time in time steps of 1 second.
The Simulink model generates some setpoints for another application that needs to be published in a CSV file.
The idea is that Simulink writes and overwrites its calculated setpoints to a CSV file after each time step of 1 second.
I struggle to find a way to achieve this, can somebody help with this?
Regards,
Damien
  댓글 수: 2
Damien Pecher
Damien Pecher 2023년 2월 20일
Thanks for your answer Mili,
Unfortunately I found the 2 links you mentioned already by myself before my post and this didn't really help me...
I need to export the data to a CSV file after each step and not only at the end of the simulation.
In addition the CSV may only have 1 line of data with the data being overwiritten after every step.

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

답변 (1개)

Anshuman
Anshuman 2023년 2월 20일
Hi Damien,
To my understanding you are trying to export the result of simulation of a Simulink model to a CSV file after every time step. There is no direct way to export simulation results to a CSV file but there are some possible workarounds.
1. To File block - This block writes your signal data to a MAT file and keep overwriting it until the simulation stops.
You can refer to this link for more detail:
Later you can convert that MAT-file to a csv file:
FileData = load('FileName.mat');
csvwrite('FileName.csv', FileData.M);
2. You can also try logging your signal data (right-click the signal and select Signal Properties) and now when you run the model and then click on Data Inspector in Review Results tab in Simulation strip, there you can find an option to export your data in a MAT-file, which you can convert into a csv file by the above approach.
Hope this helps!
  댓글 수: 1
Damien Pecher
Damien Pecher 2023년 2월 21일
Hi Anshuman,
Thanks for your input, i tried the 'To File' block before but the issue with that is that it writes a time series data with a new line after every time step.
For my application I would need only one value in the MAT file that updates after every time step.
My simulink model will run for an infinite time and calculate setpoints to control an inverter. I need to somehow export the calculated setpoints by Simulink in real time to be able to use those setpoints in a Python script...
I was expecting this to be no issue at all but this seems not so easy to achieve?

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by