How to extract and to export to Excel some variables that have been logged using To Workspace block?

9 views (last 30 days)
Good morning, I am working with a Simulink model that has been developed by Professor A.Tayyebi et al to implement several Grid-forming control techniques for inverters using the IEEE 9-Bus System as benchmark.
In order to study the dynamic of the inverters I need to monitor changes in the frequency of the system caused by an increase in the power demanded by the loads.
To that end, I am using the “To Workspace” block for logging the frequency values in the model Workspace.
The simulation time is 50 s but I only need to extract the frequency values in the time interval immediately after the increase in the load and for 500 ms, that is, the frequency values between 25 and 25.5 seconds. I intend to export said frequency values to an excel file then.
My questions are the following:
1.- Which would be the most suitable save format to extract these frequency values against time, i.e.:
Structure with time, Structure, Array or Timeseries.?
2.- Which are the most suitable commands to extract the logged time and frequency values and to export them to Excel?
An example of commands would be very welcomed indeed. Thanks in advance!

Accepted Answer

Jon
Jon on 17 Aug 2023
There are many ways to do this. I have attached a simple example showing one way to do it with the data being saved in timeseries format. Please first run the model, and then run the attached script to demonstate how it works. You should be able to adapt this approach to your specific situation.
Just so you can see it easily, here is the script for saving the data after you run the model
% Script to save output of Simulink To Workspace block
% To Workspace block saves data as TimeSeries
% Convert timeseries to timetable, to make it more convenient to export
TT = timeseries2timetable(out.y)
% Find rows of interest
tr = timerange(seconds(25),seconds(25.5));
% Export the rows of interest
writetimetable(TT(tr,:),'myFile.xlsx')
  3 Comments
JUAN ANTONIO CABEZA LÓPEZ DE TAMAYO
Dear Jon, I have checked again and it appears that the command "timeseries2timetable" was not available in the Matlab version it was installed in my PC. After updating to R2023a version, I have been able to execute the script as per your instructions and thus create the excel file as desired.
Thank you very much for your very kind support and BR!
Jon
Jon on 22 Aug 2023
Sorry I didn't see you earlier message. Glad you were able to resolve it by updating to the current MATLAB version. Good luck with your project

Sign in to comment.

More Answers (0)

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!