Asked • 07/12/19

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

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. 1st script: 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')") 2nd script: import matlab.engine eng = matlab.engine.connect_matlab('my_sim123') eng.eval("set_param('scheme123/PID', 'P', '15')",nargout=0) **UPDATE:** I tried to use `set_param('scheme123', 'SimulationCommand','Start')` instead, but the following error occured: "You cannot use set_param to run a simulation in a MATLAB session that does not have a display." Is there any other way to change the parameter of the running sumulation with no display?

1 Expert Answer

By:

Nicklas S. answered • 10/13/24

Tutor
New to Wyzant

Computer Science/Programming/English Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.