In [1]:
import os
import numpy as np
import pymatbridge as pymat
reload(pymat)


Out[1]:
<module 'pymatbridge' from '/Users/arokem/usr/lib/python2.7/site-packages/pymatbridge/__init__.pyc'>

In [2]:
matlab = pymat.Matlab()
matlab.start()


woot
Starting MATLAB on http://localhost:51435
 visit http://localhost:51435/exit.m to shut down same
...MATLAB started and connected!
Out[2]:
True

In [3]:
res = matlab.run_func('%s/matlab/www/demo_func.m'%os.path.dirname(pymat.__file__), {'a': 10})
res['result']


Out[3]:
11

In [4]:
res_dict = matlab.run_code('a=[1,3,7]')
res_dict = matlab.run_code('plot(a)')
res_dict = matlab.run_code('b=a+1')
exec('this=np.array(%s)'%matlab.get_variable('b')) 
this


Out[4]:
array([2, 4, 8])

In [5]:
res_dict = matlab.run_code('figure; plot(b); b')

from IPython.core.displaypub import publish_display_data
imgfiles = [res_dict['content']['figures']]
text_output = res_dict['content']['stdout']

display_data = []
if text_output:
    display_data.append(('MatlabMagic.matlab',
                                 {'text/plain':text_output}))
for imgf in imgfiles:
    image = open(imgf[0], 'rb').read() 
    display_data.append(('MatlabMagic.matlab',  {'image/png': image}))

for tag, disp_d in display_data:
            publish_display_data(tag, disp_d)


b =

     2     4     8


In [6]:
matlab.is_connected()


Out[6]:
True

In [7]:
matlab.stop()


MATLAB closed
Out[7]:
True

In [8]:
matlab.is_connected()


Out[8]:
False

In [ ]: