且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Matlab运行R脚本

更新时间:2023-10-21 09:14:58

您可以在MATLAB中使用system函数来执行Shell命令.由于您可以从批处理文件运行R,因此

You can use the system function in MATLAB to execute shell commands. Since you can run R from batch files,

executed = system('R CMD BATCH path/script.R')

应该工作.请注意,无论您在MATLAB中的活动目录如何,path都必须是R脚本的正确相对路径.如果系统命令成功执行(与R脚本成功执行不同,则executed的计算结果将为0.)

should work. Note that path will need to be the correct relative path to your R script from whatever your active directory in MATLAB is. executed will evaluate as 0 if the system command executed successfully (which is not the same as the R script executing successfully).