I am following this link to run matlab code in python: Running Matlab using Python gives 'No module named matlab.engine' error
I am getting the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36\lib\site-packages\matlab\engine\matlabengine.py", line 71, in __call___stderr, feval=True).result()
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36\lib\site-packages\matlab\engine\futureresult.py", line 67, in result
return self.__future.result(timeout)
File "C:\Users\XYZ\AppData\Local\Programs\Python\Python36\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)
matlab.engine.EngineError: MATLAB function cannot be evaluated
I am using Python 3.6 windows 7, 64 bit Matlab R2018b version
I have just written a simple function in matlab and saved the file as demo.m The code is here:
printk();
function printk()
fprintf(' Hello world!');
end
and saved the file as demo.mat
Python idle:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.demo(nargout=0)
Can anyone please help. I need to migrate whole bunch of codes in python. Any other possible way would be appreciated. Thanks.
fprintf? have you tried some other function that does not use MATLAB's I/O features? Perhaps you cannot write in command line using MATLAB fucntions in python