matlab - how to pass command line argument that is a matrix to R CMD BATCH -
i use rscript matlab, , want send matrix rscript command line. have read this post, examples in post passed number or small matrix or arrary. question how pass matrix rscript command line. thank 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 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)
i don't think matlab can pass data stdin of command called system. options are:
- write data out file in way can read in within rscript process (e.g. csv). potentially temporary file, , filename passed argument r script.
- encode data in cross-program way can passed command-line argument (e.g. json). however, harder implement successfully, , may run issues of maximum line length commands.
- encode data r expression can evaluated within r (e.g.
matrix(c(1, 4, 5, 2, 9, 7), nrow = 3)along lines of question linked .
unless there's reason, i'd go option 1.
Comments
Post a Comment