[英]Python and call Matlab script outside of Python with arguments
I feel like i am almost there but need the extra push! 我觉得我快到了,但需要额外的推动力! I am trying to call a MATLAB script from Python (I'm not worried about the output of the MATLAB script - it runs independently).
我正在尝试从Python调用MATLAB脚本(我不担心MATLAB脚本的输出-它独立运行)。 However, i must be able to send an input into the MATLAB script from python.
但是,我必须能够从python向MATLAB脚本发送输入。
Right now I have(in python): 现在我有(在python中):
myvartoinput = 55
cmd = 'myscript.m'
process = Popen(["matlab", "-nosplash", "-nodesktop", "-r", cmd], shell=True)
process.communicate()
# Also, how do i 'exit' the MATLAB so it doesn't continue to run
I am not sure how to add "myvartoinput" into the 'myscript.m' file. 我不确定如何将“ myvartoinput”添加到“ myscript.m”文件中。 Also, did I call the script correctly?
另外,我是否正确调用了脚本? Finally, i would like it to "exit" so it doesn't stay open in the background on my pc.
最后,我希望它“退出”,因此它不会在我的PC的后台保持打开状态。 Any help would be appreciated!
任何帮助,将不胜感激!
I have solved it differently: 我已经解决了不同的问题:
import os
import subprocess
myvartoinput = 55
subprocess.call(['matlab', '-wait','-nosplash','-nodesktop','-r','myscript(\'%s\')' %(myvartoinput )])
Arguments: 参数:
'-wait' - python waits till Matlab executes script and continues; '-wait'-python等待Matlab执行脚本并继续;
'-nodesktop' - only matlab command window is called; '-nodesktop'-仅调用matlab命令窗口;
'-nosplash' - suppresses the display of the splash screen; '-nosplash'-禁止显示初始屏幕;
'-r' - argument after which follows name of a script '-r'-后跟脚本名称的参数
More info here: http://se.mathworks.com/help/matlab/matlab_env/startup-options.html 此处的更多信息: http : //se.mathworks.com/help/matlab/matlab_env/startup-options.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.