Reputation: 43
I am attempting to run MATLAB functions from python. I am following the MathWorks Tutorial. In that tutorial they specify that output from a MATLAB script can be viewed in python. The example they give has the following code
% 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.
The python portion:
import matlab.engine
eng = matlab.engine.start_matlab()
eng.triarea(nargout=0)
The python script is supposed to print
a =
7.5000
This works perfectly when running it as a normal python script (for example, using PyCharm). However, nothing is printed when this python code is run using Jupyter notebook.
How does one get the correct output when running the python code using Jupyter notebook?
So far, I have tried specifying standard out (as suggested in here). Namely my python code now reads
import io
out = io.StringIO()
eng.triareaf(nargout=0, stdout=out)
However, I still am not able to get the correct output. I am using Python 3.5, MATLAB R2017a, Jupyter version 4.4.0 and Windows 10.
Upvotes: 3
Views: 758
Reputation: 36
If you still have the terminal open (i.e. the one in which the Jupyter Server is running) you will find there the output you are expecting.
Btw, this is not a solution but just a workaround ... still looking for a way to make the terminal output appear directly in the notebook.
Upvotes: 2