Can step size be changed during a Simulink simulation?

11 views (last 30 days)
Hi, I need to change the maximum step size in the middle of a Simulink simulation. My idea was the following:
set_param(bdroot,'FixedStep', num2str(InitialStepSize));
set_param(bdroot,'SimulationCommand','start');
% pause the simulation at a certain t by means of an _assertion block_
set_param(bdroot,'FixedStep', num2str(NewStepSize));
set_param(bdroot,'SimulationCommand','continue');
By doing so I get an error saying that the step size cannot be changed while the simulation is running. Is there any way to do this? A workaround would be to split the simulation in two parts. Simulate the first part with InitialStepSize, stop the simulation at t, save the status, and simulating with NewStepSize starting from the previously saved state. Anyway, I do not like such a solution that much.
Thank you

Answers (1)

Rishabh Gupta
Rishabh Gupta on 24 Sep 2018
Hi Gerardo,
Changing the step Size during the Simulation is not possible. There could be another workaround, but it would depend on your exact use case if it would be feasible to use that or not.
You could simulate the model at a step size as follows:
step_size = HCF (step_size_of_first_part_of_model , step_size_of_second_part_of_model).
For example :
If you want step size = 4 for first part of model and step size = 5 for second part of the model then you could simulate the model at step size = HCF(4,5) = 1.
Then you would need to manually look at the output and process it to get the model output at desired time stamps.

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!