【问题标题】:python interpreter to a MATLAB session - iPython notebookpython 解释器到 MATLAB 会话 - iPython 笔记本
【发布时间】:2024-01-03 12:57:01
【问题描述】:

我想从 iPython notebook 运行 MATLAB 代码。

我已经安装了以下库:

  • 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

我正在尝试将 MATLAB 与 iPython 连接,以便使用以下代码运行 MATLAB 命令:

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()

但是,得到了以下消息:

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

同样在运行%load_ext pymatbridge iPython-magic 命令时返回:

The pymatbridge module is not an IPython extension.

你能帮忙吗?

【问题讨论】:

  • 另外,我关注了这些directions 并输入了%load_ext pymatbridge,这会打开一个 MAtlab 命令窗口,但出现错误Error in matlabserver (line 7) messenger('init', socket_address);
  • Q1: 为了找出问题的根本原因,您是否尝试过 python-python zmq-socket 通信来证明 iPython 端的基础设施正常且工作正常? Q2:您是否尝试过使用 MATLAB 进行非 iPython python 解释器会话,以证明观察到的故障与 iPython-(in) 相关性? Q3:您之前有没有使用 MATLAB 进行 pymatbridge 或其他基于 MEX 的独立 zmq-socket 通信的经验?

标签: python matlab ipython ipython-notebook


【解决方案1】:

如果不是不可逆转地绑定到 pymatbridge,方法如下:

% 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 ...?

【讨论】: