【问题标题】:Python and call Matlab script outside of Python with argumentsPython 并在 Python 之外使用参数调用 Matlab 脚本
【发布时间】:2023-03-06 11:25:01
【问题描述】:

我觉得我快到了,但需要额外的推动!我正在尝试从 Python 调用 MATLAB 脚本(我不担心 MATLAB 脚本的输出 - 它独立运行)。但是,我必须能够将输入从 python 发送到 MATLAB 脚本。

现在我有(在 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

我不确定如何将“myvartoinput”添加到“myscript.m”文件中。另外,我是否正确调用了脚本?最后,我希望它“退出”,这样它就不会在我的电脑的后台保持打开状态。任何帮助将不胜感激!

【问题讨论】:

标签: python matlab arguments subprocess popen


【解决方案1】:

我有不同的解决方法:

import os 
import subprocess
myvartoinput = 55

subprocess.call(['matlab', '-wait','-nosplash','-nodesktop','-r','myscript(\'%s\')' %(myvartoinput )])

参数:

'-wait' - python 等待 Matlab 执行脚本并继续;

'-nodesktop' - 只调用matlab命令窗口;

'-nosplash' - 禁止显示启动画面;

'-r' - 脚本名称后面的参数

更多信息在这里:http://se.mathworks.com/help/matlab/matlab_env/startup-options.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多