Trying to run MATLAB from Python

3 views (last 30 days)
Or Shem Tov
Or Shem Tov on 14 May 2020
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'.

Answers (0)

Categories

Find more on Python Package Integration in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!