MATLAB Engine API for Python: changing parameters of the running simulation

20 ビュー (過去 30 日間)
Peter Sabol
Peter Sabol 2017 年 3 月 19 日
回答済み: Bo Li 2017 年 7 月 24 日
Hello, I am using the MATLAB Engine API for Python. I have a shared engine in a Python script and then another Python script connected to this shared engine. I would like to ask whether it is possible to change the parameter of the running simulation from Simulink using set_param command. It looks like my following solution does not work. The "set_param" command in the 2nd script is waiting until "sim()" command from the 1st script is finished. Thanks in advance.
Python script 1:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.eval("matlab.engine.shareEngine('my_sim123')")
eng.eval("load_system('scheme123')",nargout=0)
eng.eval("sim('scheme123')")
Python script 2:
import matlab.engine
eng = matlab.engine.connect_matlab('my_sim123')
eng.eval("set_param('scheme123/PID', 'P', '15')",nargout=0)

回答 (1 件)

Bo Li
Bo Li 2017 年 7 月 24 日
This looks related how you run the simulation. Instead of running "sim", you may use set_parm to star the simulation like following:
eng.set_param('scheme123', 'SimulationCommand', 'start', nargout=0)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by