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.

 採用された回答

TAB
TAB 2012 年 3 月 26 日

1 投票

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 件のコメント

Matus
Matus 2012 年 3 月 26 日
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 2012 年 3 月 26 日
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 2012 年 3 月 26 日
thank you
Kaustubha Govind
Kaustubha Govind 2012 年 3 月 26 日
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 2012 年 3 月 26 日
thank you, i will try
Matus
Matus 2012 年 3 月 29 日
Thank you Kaustubha, it works great.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

質問済み:

2012 年 3 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by