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

 Accepted Answer

This could be done by simply setting the output of simulation to be a vector.
set the max number of simulation s to be performed (i).
model = 'type_model_name_here';
load_system(model);
i = 100; % say you have 100 simulation runs
simout_a(i) = Simulink.SimulationOutput;
for j=1:i
set_param([model '/Constant1'], 'Value', num2str(var(j)));
set_param([model '/Constant2'], 'Value', num2str(var(j)^2));
set_param([model '/Constant3'], 'Value', num2str(var_2(j)));
simout_a(j) = sim(model, 'SimulationMode', 'normal');
end
When you need output for Nth simulation, just index simout(N).time or simout(N).datalog

More Answers (1)

HamidReza Saleh
HamidReza Saleh on 20 Sep 2016
Do you have any idea how to do this ?? as you can see there is a lot of parameter and three table in one what is you're suggestion ??

9 Comments

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.
I used the command simulation works fantastic but the results is in a parameter titled simout_a , how do i get parameter yout which should contain result of each time simulation ?
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.
it just replies this error :
Struct contents reference from a non-struct array object.
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.
i configure my simulation but still doesn't work here is my code please check it
model = 'PrPUPFCSVM2'; load_system(model);
% initialize fault type i = 11; % 10 faults and normal state
for j = 1:i
% Set fault type
% Altogether 10 types: AG, BG, CG, AB, BC, AC, ABG, ACG, BCG, ABCG
faultType = j;
%1 == AG
if faultType == 1
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 2
%2 == BG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 3
%3 == CG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 4
%4 == AB
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',0);
elseif faultType == 5
%5 == BC
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',0);
elseif faultType == 6
%6 == AC
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',0);
elseif faultType == 7
%7 == ABG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 8
%8 == ACG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 9
%9 == BCG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 10
%10 == ABCG
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',1);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',1);
elseif faultType == 11
%11 == No Fault
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultA',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultB',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','FaultC',0);
set_param('PrPUPFCSVM2/Three-Phase Fault','GroundFault',0);
simout_a(j) = sim(model, 'SimulationMode', 'normal');
end
end
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.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!