此示例显示如何从MATLAB重定向标准输出和标准错误®函数到python.®stryio.
对象。
在Python 2.7中,使用stryio.
模块要创建stryio.
对象。捕获警告消息Dec2Hex.
, 指定stdout.
和斯德尔
。
导入matlab.engine Eng = MATLAB.ENGINE.START_MATLAB()导入stryio out = stryio.stringio()err = stryio.stringio()ret = eng.dec2hex(2 ** 60,stdout = out,stderr = err)打印(out.getValue())
警告:输入数字中的至少一个大于最大整数值浮点数(2 ^ 52)。结果可能是不可预测的。
在Python 3.x中,使用IO.
模块要创建stryio.
对象。
导入matlab.engine eng = matlab.engine.start_matlab()导入io out = io.stringio()ero.stringio()err = Io.Stringio()Ret = Eng.Dec2Base(2 ** 60,16,STDOUT = OUT,STDERR = ERR)
Dec2Base.
当输入参数大于2 ^ 52时,提出异常。显示捕获的错误消息呃
。
打印(err.getValue())
使用Dec2Base(第22行)错误的第一个参数必须是整数数组,0 <= D <= 2 ^ 52。
matlab.engine.futureresult.futureresult.
|matlab.engine.matlabengine.