- Share an engine from MATLAB.
How to initialize the workspace for a simulink model from a python script using the matlab engine
6 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone! I've connected a python script to a simulink model as explained in this tutorial https://medium.com/@soutrikbandyopadhyay/controlling-a-simulink-model-by-a-python-controller-2b67bde744ee. What I would like to know now is: my simulink model calls some variables from the workspace, so is there a way to initialize the workspace using the matlab engine in python?
0 件のコメント
回答 (1 件)
Meet
2025 年 1 月 16 日
Hi Francesco,
To initialize the MATLAB workspace using matlab engine you could follow these steps:
matlab.engine.shareEngine('engine_1')
2. Connect the shared engine from MATLAB with python program.
import matlab.engine
eng = matlab.engine.connect_matlab('engine_1')
3. Create a python variable and initialize it to MATLAB workspace using the following command.
px = eng.linspace(0.0,6.28,1000)
eng.workspace['mx'] = px
You could find documentation for the same using this command in your MATLAB command window.
help("matlab.engine.MatlabEngine")
I hope this helps with your task!!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Call MATLAB from Python についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!