Trying to run MATLAB from Python

조회 수: 1 (최근 30일)
Or Shem Tov
Or Shem Tov 2020년 5월 14일
Hi,
I'm trying to call a MATLAB script from Python, I've been using this code:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.myScript(nargout=0)
I initiated this code after starting a MATLAB shared session using this in MATLAB:
matlab.engine.shareEngine
For some reason it doesn't work, I'm not getting any output and when I'm trying to retrieve variables from the workspace it gives me this error:
>> eng.workspace['T2']
Traceback (most recent call last):
File "<ipython-input-197-b0020f6fe85d>", line 1, in <module>
eng.workspace['T2']
File "C:\Anaconda3\lib\site-packages\matlab\engine\matlabengine.py", line 120, in __getitem__
future = _method(attr)
File "C:\Anaconda3\lib\site-packages\matlab\engine\matlabengine.py", line 71, in __call__
_stderr, feval=True).result()
File "C:\Anaconda3\lib\site-packages\matlab\engine\futureresult.py", line 67, in result
return self.__future.result(timeout)
File "C:\Anaconda3\lib\site-packages\matlab\engine\fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
MatlabExecutionError:
File C:\Program Files\MATLAB\R2020a\toolbox\matlab\external\engines\engine_api\+matlab\+internal\+engine\getVariable.m, line 27, in getVariable
Undefined variable 'T2'.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by