Simulationinput for multiple parameters design study
Show older comments
I’m trying to run a design study (Simulink model) with 2 parameters (par1,par2) sweep. I’d like it to be exhaustive in terms that 1st value/variant of par1 is run against each value/variant of par2, then 2nd value of par1 runs against each value of par1 and so on till all combinations are simulated.
I’d like to run it programmatically creating Simulationinput and using
simOut=sim(simIn).
I have no problem creating Simulationinput object if I’m using only one parameter to sweep through:
Mdl='MyModel'
Par1_sweep = [6000 7000 8000 10000 11000 12000]
numSims = numel(Par1_sweep);
% Create an array of SimulationInput objects and specify the sweep value for each simulation
simIn(1:numSims) = Simulink.SimulationInput(Mdl);
for idx = 1:numSims
simIn(idx) = simIn(idx).setBlockParameter(Mdl '/MyBlock',...
'Par1', num2str(Cr_sweep(idx)))
end
% Simulate the model
simOut = sim(simIn,'ShowSimulationManager','on','ShowProgress','on')
The above sentence in red was created when I accidentally clicked "Run". The above code works perfectly well.
Problem is that if I want to add Par2 sweep, I can’t figure out how to properly create simIn
Mdl='MyModel'
Par1_sweep=[6000 7000 8000]
Par2_sweep=[10000 11000 12000 13000]
numSims = numel(Cr_sweep).*numel(Par2_sweep);
% Create an array of SimulationInput objects and specify the sweep value for each simulation
simIn(1:numSims) = Simulink.SimulationInput(Mdl);
for idx = 1:numSims
simIn(idx) = simIn(idx).setBlockParameter(mdl'/MyBlock',...
'Par1', num2str(Par1_sweep(idx)),setBlockParameter(mdl'/MyBlock', 'Par2', num2str(Par2_sweep(idx)))
end
Above doesn’t work in terms that it doesn’t create desired simIn array. Any advise on how this should be properly written so that I get exhaustive study of Par1 and Par2 variants is highly appreciated.
Thank you.
Ted
1 Comment
Tudor Miron
on 9 Nov 2022
Answers (0)
Categories
Find more on Simulink 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!