Clear Filters
Clear Filters

How to export data from simulink

4 views (last 30 days)
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

Nihar Deodhar
Nihar Deodhar on 20 Sep 2016
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
Nihar Deodhar
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.

Sign in to comment.

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!