我对pymatbridge
有疑问。我一直在尝试使用它作为Matlab引擎的替代品,由于某些原因我最近和我haven't been able to get it to work again打破了。我按照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
失败了我的脚本,但在终端工作。顺便说一句,我在this post(向下滚动,第3个回答)的惊人回答中了解了pymatbridge
和matlab_wrapper
。