How to handle multi Matlab return values in Python
87 views (last 30 days)
I'm using Matlab 2014b, and I want to call Matlab function from Python(2.7.6). Here is my Python script:
import matlab.engine as meng
import matlab as mat
eng = meng.start_matlab()
x,y = eng.Fun_Py(3,4)
print "error in python script"
and here is my Matlab script:
function [x,y]=Fun_Py(a,b) x=zeros(a,b); y=sum(x); end
When I ran the Python scipt, I got "error in python script".How can I solve this problem? Any help is appreciate.
Bo Li on 1 Jul 2015
There are two things need to be done.
1. Add the folder where Fun_Py.m is located into MATLAB path from MATLAB command window:
Or you can change the current folder in MATLAB to where Fun_Py.m is located, for example if it is located in c:\temp:
2. Set the number of output to 2 if 2 output is expected:
x,y = eng.Fun_Py(3,4, nargout=2)