1

I want to run MATLAB code from iPython notebook.

I have installed the following libraries:

  • ZeroMQ-4.0.4-miru1.0-x64.exe
  • pyzmq-14.7.0
  • pymatbridge-0.5.2
  • matplotlib-1.4.3.win-amd64-py2.7.exe
  • python 2.7

I am trying to connect MATLAB with iPython in order to run MATLAB commands with the following code:

import sys
sys.path.append('C:\Python27\Lib\site-packages\pymatbridge')
​
​
from pymatbridge import Matlab
mlab = Matlab()
​
mlab = Matlab(executable='C:\Program Files\MATLAB\R2013a\bin\matlab')
mlab.start()

However, the following message was obtained:

Starting MATLAB on ZMQ socket tcp://127.0.0.1:42987
Send 'exit' command to kill the server
............................................................MATLAB session timed out after 60 seconds

Also when running %load_ext pymatbridge iPython-magic command returns:

The pymatbridge module is not an IPython extension.

Could you please help?

user3666197
  • 1
  • 6
  • 50
  • 92
Darkmoor
  • 862
  • 11
  • 29
  • Also, I followed these [directions](http://stackoverflow.com/questions/23716426/installing-pymatbridge-on-windows) and typed `%load_ext pymatbridge` which opened a MAtlab command window but with the error `Error in matlabserver (line 7) messenger('init', socket_address);` – Darkmoor Sep 21 '15 at 16:37
  • **Q1:** so as to isolate the root-cause of the issue, have you tried python-python zmq-socket communication to proof iPython-side infrastructure is fine and working? **Q2:** have you tried non-iPython python interpreter session with MATLAB so as to proof iPython-(in)dependence of the observed failure? **Q3:** have you gained any previous experience with pymatbridge or other MEX-based independent zmq-socket based communications with MATLAB? – user3666197 Sep 22 '15 at 14:44

1 Answers1

0

If not irreversibly bound to pymatbridge, here is the way:

% MATLAB script to setup ZeroMQ-MATLAB session ( neutral agent-to-agent PUB/SUB )

clear all;

if ~ispc
    s1 = zmq( 'subscribe', 'ipc', 'MATLAB' );   %% using IPC transport on <localhost>

else
    disp( '0MQ IPC not supported on windows. Setup TCP transport class instead' )
    disp( 'Setting up TCP' )
    s1 = zmq( 'subscribe', 'tcp', 'localhost', 5555 );

end

recv_data1 = [];                                %% setup RECV buffer

more details >>> Most efficient way to exchange data between MATLAB and ...?

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92