执行批处理文件,我有一个Matlab函数,发现其中这个功能我的电脑内的路径,然后运行在同一个目录下一个bat文件。这个bat文件是为了执行一个R脚本,但是由于一个奇怪的原因而没有这么做。从MATLAB
这是我的Matlab的功能:
function [] = myFunction(arg)
% Find the directory of the executing script
thisDir = fileparts(mfilename('fullpath'));
% Save arg as a csv on this directory, this will be read by my R script
tmpDir = strcat(thisDir,'/tmp.csv');
csvwrite(tmpDir,arg);
% Specify the command to run
dosCommand = ['call "' thisDir '/runRscript.bat"'];
dos(dosCommand);
end
BAT文件具有下面的代码:
"C:\Program Files\R\R-3.2.2\bin\x64\R.exe" CMD BATCH runRScipt.R
当我在Matlab运行功能,我得到了以下信息:
C:\用户\ ... mypath中...> “C:\ Program Files文件\ r \ R-3.2.2 \ BIN \ 64 \运行R.exe” CMD批 runRscript.R
由于我在Matlab中得到这个消息,我毫不怀疑它正在查找和读取批处理文件,但是它无法执行R脚本。我知道bat文件按预期工作,因为我可以通过命令行运行(与应在MATLAB脚本的“dosCommand”命令),或者通过在.bat文件点击两次。
[This](http://stackoverflow.com/questions/14167178/passing-command-line-arguments-to-r-cmd-batch)可能是相关的。 也有似乎是一个特定的包吧,见[这里](http://www.mathworks.com/matlabcentral/answers/31708-running-r-within-matlab)。 –