我已经通过 Python 中的 matlab.engine 隔离了写入 Matlab 工作区的问题。有人可以帮忙吗?
每当我调用 eng.workspace 时,我都会“超时”,即 Matlab 进入无限忙碌状态,无法继续使用 Python 或 Matlab 中的脚本,实际上它永远不会离开 eng.workspace 调用。
当我 ctrl-c out 命令仍然执行并且变量存储在 matlab 工作区中,但在执行该行之后什么都没有。
上下文代码:
%In Matlab
%Share the current Matlab Session
testShared = matlab.engine.isEngineShared;
if ~testShared
matlab.engine.shareEngine('MATLABShared001');
end
%Call the python script
disp('Starting call to Python Script')
cmdString = 'python test.py';
status = system(cmdString);
disp('Finished call to Python')
#In Python
import matlab.engine
names = matlab.engine.find_matlab()
eng = matlab.engine.connect_matlab(names[0])
eng.workspace['abcd'] = 10
eng.workspace['test'] = 'it worked!'
#No need to quit as python auto closes at end (and problem is before this)
如果这个 python 脚本是手动运行的(pyCharm 或 cmd\python),那么一切都会完美运行,并且这两个变量完美地位于 matlab 工作区中。但是,当从 matlab 以编程方式运行时,它会在第一个 eng.workspace 中被捕获并且不会继续。
输出(Matlab): Matlab 命令行窗口和 Ctrl-C 终止的工作区结果
任何帮助表示赞赏。
编辑:把它变成一个问题,而不是一个陈述