changing the simulation time in simulink through script

I am controlling my simulink models through MATLAB Script ,and am updating stop time through script,,,The problem here am getting is if i change any parameters value of the simulink while simulink is running,,the simulation calculation is con sidering the changed values from the initial step of the simulation,,,but rather i want my simulation to consider the new parameter value value from the step i chanf=ged while simulation is running

9 Comments

Are you saying you want to change the stop time of a Simulink model while it is running? I'd be very surprised if that was possible.
ya am updating my stop time step by step,, But i want change some parameters value of constants block through script,but my simulink model calculating from first step time,,not from the time i have changed my constant block value
So what you want to do is changing the initial state, initial time and final time so you can simulate over a longer interval in smaller steps? If so, then you can do that with the sim command, e.g.
sim('untitled','StartTime','2','StopTime','10')
starts untitled at t=2, runs it till t=10. The syntax looks weird to me, it might have changed from older Simulink/Matlab versions. Try
doc sim
no Mr Jonathan,,this I have done ,,no problem with this,,i have simulink model wher am changing parameters of some blocks,,wen i change it,,the values are taking from the starting
You will have to give it a better try of explaining, since I clearly don't get what your problem is.
What parameters of what blocks do you change, and what are the "values from the starting?"
Why are you updating stop time? what is the aim?
Arun wants to run for a while with one set of parameters, then adjust the parameters by code, then resume running from that point but with the new set of parameters and without having the simulation restart.
I guess this is want Arun is trying to say:
He wants to and is able to update certain parameters while the simulation is in progress, suppose at T=500.
But the simulation result indicates that Simulink ran the entire simulation based on the updated parameters only, while he expected both the previous (T=0 to 500) and the updated parameters (T=500 to end) to have a bearing on the result.
Yes both Mr Walter and Mr Vishal are right,,,do u have any idea?

Sign in to comment.

 Accepted Answer

TAB
TAB on 11 Dec 2012
Edited: TAB on 11 Dec 2012
I am not sure how you are managing to change the simulation time during simulation.
But for your parameter value problem :
Simulink evaluates all the parameters values before the start of simulation. See first step of Model compilation.
If you change any parameter during simulation, simulink will not notice it. To tell the simulink to re-calculate the parameters/interfaces, you have to give update command.
After you change the parameter value from scrip, give command
set_param('YourModel', 'SimulationCommand', 'update')

5 Comments

am opening and simulating my models with 'sim' command from one gui button called'start',,,and i have one more button for stoping the simulation,,,called 'stop' button ,,in my stop button i have a given command stop to stop the simulations ,,but my simulation is not stopping,rather its simulating up to time steps how much i mention under start button
TAB
TAB on 11 Dec 2012
Edited: TAB on 11 Dec 2012
Please start a new thread (question) for new query and provide some details or part of your code to support your question (like - which command are you using to stop the simulation).
for i=1:1:inf set_param('course_speed_position','StopTime', sprintf('%d',i)); set_param('course_speed_position1','StopTime',sprintf('%d',i)); simOut = sim('model1.mdl'); simOut1 = sim('model2.mdl'); end ,,,,this is the code wher am calling tow models to simulate,, and after some time i have to pause the simulation and am changing some values in workspace,,,those changed value will be taken by my simulink models,,bu wen these models take value they are giving me response from in initial time,,not the time wher i have changed the values of blocks end
for i=1:1:inf
set_param('course_speed_position','StopTime', sprintf('%d',i));
set_param('course_speed_position1','StopTime',sprintf('%d',i));
simOut = sim('model1.mdl');
simOut1 = sim('model2.mdl');
end
This loop will run forever and will never return. Then how will you run other command to pause the model, update parameter etc ???

Sign in to comment.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Products

Tags

Asked:

on 11 Dec 2012

Commented:

on 5 Jun 2014

Community Treasure Hunt

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

Start Hunting!