Monte Carlo simulations can be performed using Stateflow charts integrated with Simulink and MATLAB. Below is a simple implementation example where a Stateflow chart accepts the output's initial value as its input and generates a step signal with a step size of 1.
In this configuration:
- A Constant block supplies the Stateflow chart input, sourcing values from workspace variable x_const
- The chart output routes to the base workspace via a To Workspace block
Following model setup, simulations can be executed from MATLAB using this script:
simOut = sim('modelName.slx');
plot(simOut.y,'DisplayName',"Input = "+num2str(x_const))
The resulting figure demonstrates Monte Carlo simulation outputs:
For additional guidance on running multiple Simulink simulations, kindly access the doc page using this command:
web(fullfile(docroot, 'simulink/ug/run-multiple-simulations.html'))