How to extract and to export to Excel some variables that have been logged using To Workspace block?
10 views (last 30 days)
JUAN ANTONIO CABEZA LÓPEZ DE TAMAYO on 17 Aug 2023
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!
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