Simulation status is stopped but I cannot start new simulation from script because Matlab assumes it is still running

12 views (last 30 days)
Hi,
I have a problem with running a Simulink model from script many times in a row. While running a simulation I check in a timer update function with get_param(SimName, 'SimulationStatus'), if the model's status is 'stopped' or not, and if it is 'stopped' I save the output data, change some variables, and try to run the simulation again with set_param(SimName, 'SimulationCommand', 'start'). This mostly works fine but sometimes (it seems quite stochastic, so I really do not know what could cause it) I catch the following error: 'Cannot start a new command line simulation while a simulation has started for the same model.'
Could anyone please tell me what the source of the problem is and if there is any solution for it. Thank you in advance.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 13 Jul 2023
Might it be too fast to re-start the simulation? There could be some post-simulation processing going on.
Anyway, in the M-script, add a pause(3) statement before re-starting the simulation to see if it improves.

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!