1

I am testing calling Python functions through MATLAB, but I am not getting what I expected. I figured I could call a Python function within MATLAB and have whatever that function returns, given to a MATLAB variable, as follows:

Python script (saved as test_for_mlab.py):

def out_func(arg_1):
    print 'This print statement is in Python'
    a = int(arg_1 * 10)
    return a

MATLAB part:

val = py.test_for_mlab.out_func(33);

I was expecting val to have a value of 330 (int). Instead, the message I get in MATLAB is val = Python NoneType with no properties. None.

How can I get my desired results?

Leo
  • 45
  • 7
  • 2
    It might help to refer to https://stackoverflow.com/questions/1707780/call-python-function-from-matlab – Hugh Bothwell Feb 01 '18 at 01:24
  • 1
    I get a `Python int with properties: ...` which has value 330, as expected. Using MATLAB R2017a and Python 3.6 from Anaconda. – hbaderts Feb 01 '18 at 07:04
  • @hbaderts Maybe it doesnt work for me because I am using Python 2.7. Strange that I am able to get print outputs into MATLAB but not return variables. – Leo Feb 01 '18 at 18:50
  • EDIT: Nevermind. Now it works. Not sure what happened, but restarting AND reloading the module worked. – Leo Feb 01 '18 at 19:13

0 Answers0