Trying to run MATLAB from Python
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Python Package Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!