MATLAB: Can I call the own custom Matlab functions from python (R2014b)

enginepythonr2014b

I've just installed R2014b and am hoping to use the new MATLAB Engine for Python capabilities.
I can successfully call standard functions like isprime from python as shown in the documentation.
Is it possible for me to call my own custom Matlab functions from python using the Engine?

Best Answer

Yes, you can also call your own custom MATLAB function from Python Engine. However, you need to add the folder of your own MATLAB file (for example c:\demo\foo.m) into MATLAB path:
>>>eng.addpath(r'c:\demo',nargout=0)
>>>eng.foo()
or change to the directory where your MATLAB file is located:
>>>eng.cd(r'c:\demo')
>>>eng.foo()
If you already have the folder of your MATLAB file in the search path, you can call it directly from Python:
>>>eng.foo()