【发布时间】:2015-09-26 02:19:07
【问题描述】:
我想使用 MATLAB 中的Rscript,我想通过命令行向Rscript 发送一个矩阵。我读过this post,但这篇文章中的例子只是传递了数字或小矩阵或数组。所以我的问题是如何通过命令行将矩阵传递给Rscript。提前谢谢!
MATLAB 中的代码:
data=dlmread('test.txt')
data =
5 5 477
5 300 696
5 595 227
195 5 646
195 300 606
195 595 783
system('Rscript.exe test.R data');
R 中的代码:
options(echo=TRUE) # if you want see commands in output file
args <- commandArgs(trailingOnly = TRUE)
if(length(args)==0)
{
print("No arguments supplied.")
}
print(args)
a1 <- as.numeric(args[1])
a1 <- data.frame(a1)
print(a1)
【问题讨论】: