control simulink from mfile

Hi, I would like to control simulink from m-file. I wrote m-file. I start simulation (from m-file) and then I need after some time to stop simulation and change some input parameters and then continue. Is it possible? I have been looking for information about that but I havent been successful. e.g. I have a model in simulink which contains voltage source and resistance. Simulation runs 10 seconds. I would like to change every second peak amplitude of voltage source. I could use e.g. programmable voltage source but I would like to do it by means of m-file. Thank you in andvance.

 Réponse acceptée

TAB
TAB le 26 Mar 2012

1 vote

To start, stop, pause, and update your model from m-file you can use
set_param('YourModel', 'SimulationCommand', 'cmd');
Where cmd could be
start - To start simulation
stop - To stop simulation
pause - To puase simulation
continue - To continue from puase
update - To update the model

6 commentaires

Matus
Matus le 26 Mar 2012
Thank you for your answer but I have still a problem to solve my mfile.
After I write
set_param('YourModel', 'SimulationCommand', 'Start');
I dont know, where to define time to pause simulation (I need to stop simulation to change parameters and then run). Is there a way how to define time of pause in cmd
set_param('YourModel', 'SimulationCommand', 'Pause')?
Is it possible to set time of simulation in cmd by means of set_param(.....)?
I use sim('YourModel',time).
Thank you.
regards
Matus
TAB
TAB le 26 Mar 2012
As far as i know, there is no option for puasing simulation at a specific time. You only can set the stop time to stop simulation at a specific time.
You can change the simulation stop time using using command set_param('YourModel','StopTime','Value').
Also you can read the current simulation time in the script using get_param(YourModel,'SimulationTime') and apply the logic whatever you want.
Matus
Matus le 26 Mar 2012
thank you
Kaustubha Govind
Kaustubha Govind le 26 Mar 2012
Since you are presumably changing only tunable parameters, you could also try using the SimState (save/restore) feature. First run your model to a certain time (say t=10) and save the final state using SimState. Then, change the tunable parameters as needed, load the SimState and run the model upto t=20. If the SimState is valid (ie. the only changes in your model since the SimState has been saved is the values of tunable parameters), the simulation will run from t=10 to t=20 only.
Matus
Matus le 26 Mar 2012
thank you, i will try
Matus
Matus le 29 Mar 2012
Thank you Kaustubha, it works great.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur General Applications dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by