Redirect Standard Output and Error to Python - MATLAB & Simulink (original) (raw)

Main Content

This example shows how to redirect standard output and standard error from a MATLAB® function to Python® StringIO objects.

Use the io module to create StringIO objects.

import matlab.engine
eng = matlab.engine.start_matlab()
import io
out = io.StringIO()
err = io.StringIO()
ret = eng.dec2base(2**60,16,stdout=out,stderr=err)

dec2base raises an exception when an input argument is greater than 2^52. Display the error message captured in err.

Error using dec2base (line 22) First argument must be an array of integers, 0 <= D <= 2^52.

See Also

matlab.engine.MatlabEngine | matlab.engine.FutureResult

Topics