将非字符串参数从python传递给Matlab

时间:2015-09-15 06:00:37

标签: python

我能够在Win 7机器上从python传递string(path)参数到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'),退出"

但是,现在,我需要传递一个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'),退出"

其中 Python_list 被视为字符串。

我该怎么做?
sedy

1 个答案:

答案 0 :(得分: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\"'