How I can run a simulink model from Python script?

Hi, I'm trying to write a script in Python that generate number of inputs, and use them as inputs in a Simulink model. My doubt is how to run a Simulink model from Python (I'm working in windows). Could someone help me?
Thanks

2 件のコメント

sonali umare
sonali umare 2020 年 2 月 6 日
how can I import IEEE distribution system of MATLAB in python
Meng Zhang
Meng Zhang 2021 年 12 月 1 日
how to run the simulnk model just for one step by using MATLAB Engine API?

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

 採用された回答

Bo Li
Bo Li 2016 年 9 月 22 日

3 投票

You may consider MATLAB Engine API for Python:
For example:
>>>import matlab.engine
>>>eng = matlab.engine.start_matlab()
>>>eng.sim("vdp")

5 件のコメント

Alessandra Cuneo
Alessandra Cuneo 2016 年 9 月 22 日
Thanks! Do you also know how I can take a variable from the Workspace of Matlab (after the simulation finish to run) as pass it to Python?
Bo Li
Bo Li 2016 年 9 月 22 日
Use workspace like following:
>>>import matlab.engine
>>>eng = matlab.engine.start_matlab()
>>>x = 4.0
>>>eng.workspace['y'] = x
>>>python_y = eng.workspace['y']
More infor:
Ali Baheri
Ali Baheri 2017 年 3 月 13 日
Would you please illustrate how can I use "set_param" command in python to call Simulink file?
Wade
Wade 2018 年 4 月 9 日
I did it in this way:
>> import matlab.engine
>> Matlab = matlab.engine.start_matlab('-desktop')
>> h = Matlab.new_system('NewModelName')
>> s = Matlab.add_block('simulink/Sources/From Workspace',NewModelName+'/DataIn')
>>Matlab.set_param(NewModelName+'/DataIn','Position',matlab.double([150,150,250,250]),nargout=0)
Indhu Priyadharshini Govindasamy
Indhu Priyadharshini Govindasamy 2022 年 1 月 13 日
I tried in python like you commented before .it is working completely fine but
i want to run the simulink model in C code and Engine Api
I could find any reference for that.Could you please help me?

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

その他の回答 (1 件)

Meng Zhang
Meng Zhang 2021 年 12 月 1 日

0 投票

how to run the simulnk model just for one step by using MATLAB Engine API?

カテゴリ

質問済み:

2016 年 9 月 21 日

コメント済み:

2023 年 1 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by