Passing variables from MATLAB to Python

조회 수: 62 (최근 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']

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call 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