I would like to use Rscript
from MATLAB, and I want to send a matrix to Rscript
by command line. I have read this post, but examples in this post were just passed number or small matrix or arrary. So my question is how to pass a matrix to Rscript
by command line. Thank you in advance!
Code in 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');
Code in 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)