How to export data from simulink
显示 更早的评论
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
采纳的回答
更多回答(1 个)
HamidReza Saleh
2016-9-20
0 个投票
9 个评论
Nihar Deodhar
2016-9-20
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
2016-9-20
HamidReza Saleh
2016-9-20
Nihar Deodhar
2016-9-21
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
2016-9-21
Nihar Deodhar
2016-9-21
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
2016-9-21
Nihar Deodhar
2016-9-22
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
2016-9-22
类别
在 帮助中心 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
