我有一个关于pymatbridge
. 我一直在尝试将它用作 Matlab 引擎的替代品,由于某种原因,它最近对我产生了影响,我无法让它再次工作。我按照Github的说明进行操作,在终端中测试我的脚本时,zmq 连接运行良好,并且每次都建立连接。但是,当我将终端中的工作内容复制粘贴到 python 脚本中时,连接每次都会失败。我对 zmq 不熟悉,但问题似乎是系统性的,所以我想知道我是否缺少明显的东西。这是我的代码。
import os
import glob
import csv
import numpy as np
import matplotlib.pylab as plt
#Alternative to matlab Engine: pymatbridge
import pymatbridge as pymat
matlab = pymat.Matlab(executable='/Applications/MATLAB_R2015a.app/bin/matlab')
#Directory of Matlab functions
Matlab_dir = '/Users/cynthiagerlein/Dropbox (Personal)/Scatterometer/Matlab/'
#Directory with SIR data
SIR_dir = '/Volumes/blahblahblah/OriginalData/'
#Directory with matrix data
Data_dir = '/Volumes/blahblahblah/Data/'
#Create list of names of SIR files to open and save as matrices
os.chdir(SIR_dir)
#Save list of SIR file names
SIR_File_List = glob.glob("*.sir")
#Launch Pymatbridge
matlab.start()
for the_file in SIR_File_List:
print 'We are on file ', the_file
Running_name = SIR_dir + the_file
image = matlab.run_func('/Users/cynthiagerlein/Dropbox\ \(Personal\)/Scatterometer/Matlab/loadsir.m', Running_name)
np.savetxt(Data_dir+the_file[:22] + '.txt.gz',np.array(image['result']) )
我最终改用matlab_wrapper,它运行良好,安装和设置容易得多,但我只是想了解为什么pymatbridge
我的脚本失败但在终端中工作。顺便说一句,我在这篇文章的惊人答案(向下滚动,第三个答案)pymatbridge
中了解了这两者。matlab_wrapper