Best practice to preallocate for exporting simulation data

2 Ansichten (letzte 30 Tage)
Joan Vazquez
Joan Vazquez am 30 Mai 2018
Beantwortet: Jan am 30 Mai 2018
I want to run several Simulink simulations of the same model, with different parameters, and store all the logged data in all the simulations for further analysis in the workspace. I have read the different approaches to export simulation data. In a for sim() end approach, what should we preallocate? logsout and tout are structures, so how do I preallocate a structure of structures? Is there a better approach to achieve the same?
preallocation_logs = ???????;
preallocation_times = ???????;
for i=1:number_of_simulations
% (update some simulation parameter here)
sim('simulink_model');
preallocation_logs(i) = logsout;
preallocation_times(i) = tout;
end

Akzeptierte Antwort

Jan
Jan am 30 Mai 2018
preallocation_logs = cell(1, number_of_simulations);
preallocation_times = cell(1, number_of_simulations);
for k = 1:number_of_simulations
% (update some simulation parameter here)
sim('simulink_model');
preallocation_logs{:} = logsout;
preallocation_times{:} = tout;
end
With a cell array you do not have any limitations of the output. You can concatenate the result afterwards easily by a cat command.

Weitere Antworten (0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by