【问题标题】:passing non string parameter from python to Matlab将非字符串参数从 python 传递到 Matlab
【发布时间】:2015-09-15 06:00:36
【问题描述】:

我能够在 Win 7 机器上将字符串(路径)参数从 python 传递给 matlab 脚本(并且脚本在 新的 matlab 命令窗口中成功运行)

matlab_cmd_string = MatlabExePth+ " -nosplash -nodesktop -wait -logfile   FileIoReg_MatlabRemoteRun.log -minimize -r "
mat_file = "tst_script"
tstPth = 'C\\SVN\\Matlabcode\\tst1'
mat_cmd = matlab_cmd_string + "\"" + mat_file + "("+ "\'" +  tstPth + "\'" + ")" + ", exit\""

所以上面的计算结果为

"C:\Program Files\MATLAB\R2013b\bin\matlab.exe" -nosplash -nodesktop -wait -logfile FileIoReg_MatlabRemoteRun.log -minimize -r "tst_script('C\SVN\Matlabcode\tst1'), exit"

但是,现在,我需要传递一个 List(它成为 matlab 单元数组)作为参数,以便将 Matlab 称为

tst_script1(Python_list)

然而,在 python 中应该作为参数传递的是列表值, 而不是像

"C:\Program Files\MATLAB\R2013b\bin\matlab.exe" -nosplash -nodesktop -wait -logfile FileIoReg_MatlabRemoteRun.log -minimize -r "tst_script1('Python_list'), exit"

其中Python_list被当作一个字符串。

我该怎么做?
赛迪

【问题讨论】:

    标签: python


    【解决方案1】:

    这里,这应该适合你。

    a = [1,2,3,4,5,6] 
    matlab_cmd_string = MatlabExePth+ " -nosplash -nodesktop -wait -logfile   FileIoReg_MatlabRemoteRun.log -minimize -r "
    mat_file = "tst_script"
    tstPth = 'C\\SVN\\Matlabcode\\tst1'
    listToBePassed = str(a)
    mat_cmd = matlab_cmd_string + '\"' + mat_file + '(' + listToBePassed + ')' + ', exit\"'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 2018-08-05
      • 2020-05-28
      • 1970-01-01
      • 2021-08-13
      • 2018-04-09
      • 1970-01-01
      相关资源
      最近更新 更多