[R] R.matlab package help

michael tufemichael at gmail.com
Fri Aug 27 18:38:49 CEST 2010


Henrik,
           Thanks for your reply. I am using Matlab version
7.9.0(R2009b). This is my first try using R.matlab. I started matlab
in the same machine, and I run the MatlabServer.m in matlab, here is
my code in R:

library(R.matlab)
library(MASS)
matlab <- Matlab()
open(matlab)
setVerbose(matlab, -2)
setOption(matlab, "readResult/interval", 10);
setOption(matlab, "readResult/maxTries", 30*(60/10));

y<-matrix(rnorm(100),100,1)
x<-matrix(rnorm(200),100,1)
z<-matrix(rnorm(200),100,2)

setVariable(matlab, y=y,remote=FALSE)
setVariable(matlab, x=x,remote=FALSE)
setVariable(matlab, z=z,remote=FALSE)
evaluate(matlab,"B=TSLS(y,x,z);")
evaluate(matlab,"B")
B <- getVariable(matlab, "B",remote=FALSE)


where TSLS is a matlab function that is already written and sitting in
the working folder. The code works fine until the last command,
getVariable function, where it returns an error:

??? Error: A MATLAB string constant is not terminated properly.

Error in ==> MatlabServer at 197
      eval(expr);

In R:
   Retrieving variables from the Matlab server: 'B'
   Sending expression on the Matlab server to be evaluated...:
'variables = {'B'};'
   Received an 'OK' reply (0) from the Matlab server.
   Evaluated expression on the Matlab server with return code 0.
   Asks the Matlab server to send variables via the local file system...
   Error in file(con, open = "rb") : invalid 'description' argument


Thanks,

Michael



More information about the R-help mailing list