Matlab


In [1]:
print('''Matlab usage:

    %%matlab
    a = 1

or
    results = mlab.run_code('a=1;')

or

    res = mlab.run_func('path/to/function.m', {'arg1': 3, 'arg2': 5})

See https://github.com/arokem/python-matlab-bridge#usage for more details.
''')


Matlab usage:

    %%matlab
    a = 1

or
    results = mlab.run_code('a=1;')

or

    res = mlab.run_func('path/to/function.m', {'arg1': 3, 'arg2': 5})

See https://github.com/arokem/python-matlab-bridge#usage for more details.


In [2]:
from pymatbridge import Matlab
mlab = Matlab()
mlab = Matlab(matlab='/Applications/MATLAB_R2014a.app/bin/matlab')
%load_ext pymatbridge


Starting MATLAB on ZMQ socket ipc:///tmp/pymatbridge
Send 'exit' command to kill the server
.................................................
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-25f04e1cac26> in <module>()
      2 mlab = Matlab()
      3 mlab = Matlab(matlab='/Applications/MATLAB_R2014a.app/bin/matlab')
----> 4 get_ipython().magic(u'load_ext pymatbridge')

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2203         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2204         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205         return self.run_line_magic(magic_name, magic_arg_s)
   2206 
   2207     #-------------------------------------------------------------------------

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2124                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2125             with self.builtin_trap:
-> 2126                 result = fn(*args,**kwargs)
   2127             return result
   2128 

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
     61         if not module_str:
     62             raise UsageError('Missing module name.')
---> 63         res = self.shell.extension_manager.load_extension(module_str)
     64 
     65         if res == 'already loaded':

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/extensions.pyc in load_extension(self, module_str)
     98                     __import__(module_str)
     99             mod = sys.modules[module_str]
--> 100             if self._call_load_ipython_extension(mod):
    101                 self.loaded.add(module_str)
    102             else:

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/IPython/core/extensions.pyc in _call_load_ipython_extension(self, mod)
    145     def _call_load_ipython_extension(self, mod):
    146         if hasattr(mod, 'load_ipython_extension'):
--> 147             mod.load_ipython_extension(self.shell)
    148             return True
    149 

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/pymatbridge/matlab_magic.pyc in load_ipython_extension(ip, **kwargs)
    257     global _loaded
    258     if not _loaded:
--> 259         ip.register_magics(MatlabMagics(ip, **kwargs))
    260         _loaded = True
    261 

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/pymatbridge/matlab_magic.pyc in __init__(self, shell, matlab, maxtime, pyconverter, cache_display_data)
     98 
     99         self.Matlab = pymat.Matlab(matlab, maxtime=maxtime)
--> 100         self.Matlab.start()
    101         self.pyconverter = pyconverter
    102 

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/pymatbridge/pymatbridge.pyc in start(self)
    133 
    134         # Test if connection is established
--> 135         if (self.is_connected()):
    136             print "MATLAB started and connected!"
    137             return True

/Users/arve/Dokumenter/git/FY3490/.vs.env/lib/python2.7/site-packages/pymatbridge/pymatbridge.pyc in is_connected(self)
    173             except zmq.ZMQError:
    174                 np.disp(".", linefeed=False)
--> 175                 time.sleep(1)
    176                 if (time.time() - start_time > self.maxtime) :
    177                     print "Matlab session timed out after %d seconds" % (self.maxtime)

KeyboardInterrupt: 

In [ ]: