Simulationinput for multiple parameters design study

2 views (last 30 days)
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')
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
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
Tudor Miron on 9 Nov 2022
In a fallow up to my question. Surely I can do it (exhaustive study) using multiple simulation panel in Simulink but still I'd love to learn how to do it programatically.
Thank you,
Ted

Sign in to comment.

Answers (0)

Categories

Find more on Transportation Engineering in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!