I'm using Matlab's COM interface from python like this:
import win32com.client
mlab = win32com.client.Dispatch('matlab.application')
mlab.visible = True
print(mlab.Execute("1 + 1"))
When I run the code above it correctly prints ans = 2
but Matlab (Command Window) exits after executing the code. I want to open just one Matlab instance and send commands to it rather than launching a new Matlab session each time. Is there a way to achieve this? For the record I'm on Windows using Python 3.4.3 and Matlab R2014A.
答案 0 :(得分:2)
它是退出matlab的mlab
的析构函数。保留此变量,您的matlab会话将保持打开状态。
我建议只调度一次并在任何需要的地方使用此com实例,这样垃圾收集器将完全按照您的意愿执行,一旦不再使用它就关闭matlab。