Passing variables from MATLAB to Python

24 ビュー (過去 30 日間)
Matt Smith
Matt Smith 2022 年 6 月 29 日
コメント済み: Matt Smith 2022 年 6 月 30 日
As part of a MATLAB programme I am writing, I utilise a python script. I would like to allow the user to configure parameters in MATLAB for use in that python script.
I have been completely unable to figure out how to send MATLAB variables to python, or rather, how to pull MATLAB variables in a python script. I have a variable x in MATLAB that I wish to use in python.
import matlab.engine
eng = matlab.engine.start_matlab()
The above code works but any step I have tried beyond that has not worked.
Any help would be much appreciated!

採用された回答

Kojiro Saito
Kojiro Saito 2022 年 6 月 30 日
You might use shared MATLAB session (document link).
Run this code in MATLAB.
matlab.engine.shareEngine
Then get a variable from workspace in Python code.
import matlab.engine
eng = matlab.engine.connect_matlab()
x = eng.workspace['x']
  1 件のコメント
Matt Smith
Matt Smith 2022 年 6 月 30 日
Amazing! Thank you.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by