Changing initial conditions of a Simulink model when simulating using a for loop
8 views (last 30 days)
Show older comments
I am trying to run a vehicle simulink model (taken from here) for 5 seconds. When I try running it directly, the response seems to make sense.
However, when I use a for loop to do the same using a for loop (see attached runExample.m), the response is quite different. My assumption is I am not changing the initial conditions after each loop properly. Is there a way to update the initial conditions automatically instead of the way I am doing it, i.e., manually? What other ways could I trye to have the same responses with and without the for loop?
All the relevant files are uploaded. Simply set runDirect in the runExample.m file to true to run without the for loop, otherwise, set it to false.
Thanks in advance for your time. Looking forward to get some solution.
3 Comments
Answers (1)
Paul
on 11 Jun 2023
Why do you want to do this: instead of running the whole model in one-go, run the model for each time step, i.e., dt = 0.1 s, using for loop by passing the final boundary condition as the initial boundary condition at the end of the loop.
Is there a need to take action at the end of one time step and before starting the simulation for the next time step? Asking because there may be an alternative to accomplish whatever the goal is.
4 Comments
Paul
on 14 Jun 2023
In this line
set_param(DynamicModel, 'SaveFinalState', 'on', 'FinalStateName', 'xfinal', 'SaveFormat', 'Structure with time')
DynamicModel is not in quotes as would be typical in set_param usage. Are you sure it shouldn't be
set_param('DynamicModel', 'SaveFinalState', 'on', 'FinalStateName', 'xfinal', 'SaveFormat', 'Structure with time')
See Also
Categories
Find more on Manage Design Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!