Trying to run MATLAB from Python

3 次查看(过去 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 中查找有关 Python Package Integration 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by