使用Jupyter笔记本MATLAB代码查看输出从Python中运行

问题描述 投票:2回答:1

我试图从Python的运行MATLAB功能。我下面的MathWorks Tutorial。在该教程它们指定从MATLAB脚本,输出可在Python进行查看。他们给出的例子具有下面的代码

% This code is in a MATLAB script called triarea.m
b = 5;
h = 3;
a = 0.5*(b.* h) % Notice that there is no semicolon to suppress output.

蟒部分:

import matlab.engine
eng = matlab.engine.start_matlab()
eng.triarea(nargout=0)

该Python脚本应该打印

a =

    7.5000

运行时,它作为一个正常的python脚本(例如,使用PyCharm)这完全适用。然而,当这条巨蟒代码使用Jupyter笔记本运行印什么。

如何运行使用Jupyter笔记本的Python代码当一个人得到正确的输出?

到目前为止,我已经试过指定标准输出(如here建议)。也就是说我的Python代码现在读

import io
out = io.StringIO()
eng.triareaf(nargout=0, stdout=out)

但是,我依然没能得到正确的输出。我使用Python 3.5,MATLAB R2017a,Jupyter版本4.4.0和Windows 10。

python python-3.x matlab jupyter-notebook jupyter
1个回答
2
投票

如果您仍然有终端开放(即在其中的Jupyter服务器正在运行),你会发现有你期望的输出。

顺便说一句,这不是一个解决方案,但只是一个解决办法...仍在寻找一种方法,使端子输出直接出现在笔记本上。

© www.soinside.com 2019 - 2024. All rights reserved.