How to export data from simulink
Show older comments
Hi
Im trying to export data from my simulink i created an M-file that use For loops and set_param command to configure different setting such as different KM different resistance for fault ... etc then run Simulink and get data as this M-file uses for loop my first concern is overwriting data and by it i mean losing some data ? would this happen ? considering that i use several out block that fill yout parameter , do you gusy have some idea or suggestion for this ?? is there any that i can gather data from my simulink model without configuring and ruining by manual for several times ??
thanks
Accepted Answer
More Answers (1)
HamidReza Saleh
on 20 Sep 2016
0 votes
9 Comments
Nihar Deodhar
on 20 Sep 2016
There could be several ways to access the output. First of all I would like to know the format in which you get output for a single simulation. Is it just tout and yout as timeseries, or is it a set of arrays of the form structure with time? The data extraction process will be different in each case. I have provided a code snippet below for the case when output is taken as 'structure with time'.
Lets say you have the variable names in your simulink model that you mentioned above.
for k = 1:100
fault_inception_angle_temp = simout_a(k).get('fault_inception_angle');
fault_inception_angle(k,:) = fault_inception_angle_temp.signals.values;
end
and so on for different variables. If you have a different output type, like timeseries or some other structure, then the code could be slightly modified to extract/process the output for each simulation.
HamidReza Saleh
on 20 Sep 2016
HamidReza Saleh
on 20 Sep 2016
Nihar Deodhar
on 21 Sep 2016
if you want to see the output for simulation 1,
simout_a(1).get('yout').signals.values
the above command will give you the output.
HamidReza Saleh
on 21 Sep 2016
Nihar Deodhar
on 21 Sep 2016
There might be something else going on with the way you are logging your data. I save it as 'Structure with time' for which case the above code literally works fine. Here is a snapshot of what I mean. There is an option to set the format.

HamidReza Saleh
on 21 Sep 2016
Nihar Deodhar
on 22 Sep 2016
First off I did not see a line at the beginning that say something like:
simout_a(i) = Simulink.SimulationOutput;
Ok, lets say you have it somewhere (because you have to initialize the output array).
Furthermore, You are adding output to simout_a only in one case (j=11). Doing this will only give you one simout_a(11) struct with contents and the others will be empty. So I think what you intend to have is the sim command outside of if-else statement. Aslo, if-else statement chain should have the last 'else condition' not an 'elseif'. This is not a thumb rule, but just wanted to add the last point.
HamidReza Saleh
on 22 Sep 2016
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!