%% Step1
% setup the active variant selection for each variant choice
% and set the number of simulation run equal to the variant selections

%   Copyright 2021 The MathWorks, Inc.

mdl = 'slexVariantSubsystemsWithParSim';
open_system(mdl);
numSims = 2;
varControl = [1,2];

%% Step 2
% create the SimulationInput object for each simulation run
% and set the Variant Control value for each run
in(1:numSims) = Simulink.SimulationInput(mdl);
for idx = 1:numSims
    in(idx) = in(idx).setModelParameter('SimulationMode', 'rapid', ...
                'RapidAcceleratorUpToDateCheck', 'on', ...
                'SaveTime', 'on', ...
                'SaveOutput', 'on');
    in(idx) = in(idx).setVariable('VSS_MODE',varControl(idx));
end

%% Step 3
% Using parsim Simulate the model in parallel for each variant control value 
out = parsim(in, 'ShowProgress', 'on');

%% Step 4
% Now plot the output values each run
for i = 1:numSims
    simOut = out(i);
    t = simOut.tout;
    y = simOut.yout;
    plot(t, y)
    hold all
end
