error output from python matlab engine

조회 수: 19 (최근 30일)
Jeremy Rutman
Jeremy Rutman 2016년 1월 13일
댓글: Jeremy Rutman 2016년 1월 27일
I'd like to get better debug info than the 'matlab function cannot be evaluated' that I currently see from a complex matlab function being run from python using the python matlab engine. Is there some way to pipe extra matlab debug output to a file and/or get more info ?
  댓글 수: 2
Stephen23
Stephen23 2016년 1월 13일
편집: Stephen23 2016년 1월 13일
The documentation
states that you should get the whole MATLAB error message from the Python Engine: "When a MATLAB® function raises an error, the MATLAB Engine for Python® stops the function and catches the exception raised by MATLAB. The engine copies the error message to a new Python exception. The engine raises the Python exception."
That page gives several examples of this.
What other information would you like?
Jeremy Rutman
Jeremy Rutman 2016년 1월 27일
pretty much anything beyond 'matlab function cannot be evaluated' would be great - i've been using
out = StringIO.StringIO()
err = StringIO.StringIO()
retvals = matlab_engine.myfunc(image_filename, nargout=3,stdout=out,stderr=err)
outstring = out.getvalue()
errstring = err.getvalue()
logging.debug('ml output:'+str(outstring)+'\n')
logging.debug('ml err output:'+str(errstring)+'\n')

댓글을 달려면 로그인하십시오.

답변 (1개)

Robert Snoeberger
Robert Snoeberger 2016년 1월 15일
You could get the last uncaught exception [1] and then call getReport [2] to get the error message for that exception.
Example
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>>
>>> # Do something that throws an exception...
>>>
>>> eng.eval('exception = MException.last;', nargout=0)
>>> eng.eval('getReport(exception)')
References

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by