[R] R.matlab package help

Henrik Bengtsson hb at stat.berkeley.edu
Sun Aug 29 01:48:46 CEST 2010


Hi.

On Sat, Aug 28, 2010 at 3:50 PM, michael <tufemichael at gmail.com> wrote:
> Henrik,
>           OK, finally I got the problem:  I have an  apostrophe in my
> windowns 7 user name. That mess up the file name. So I logged in using a
> guest account and it works:
>
> Received cmd: 1
> "eval" string: "B"
> B =
>   -0.1347
> Sent byte: 0
> Received cmd: 1
> "eval" string: "variables = {'B'};"
> Sent byte: 0
> Received cmd: 2
> save tempname-V6 B
> answer=0
>
> Thanks a lot for your patience and help.

Good that you found a workaround.

> One final question, the variable B I got from Matlab is not just a numeric
> value, it is:
>
>> B
> $B
>           [,1]
> [1,] -0.1346952
> attr(,"header")
> attr(,"header")$description
> [1] "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Sat Aug 28 18:40:26
> 2010                                                  "
> attr(,"header")$version
> [1] "5"
> attr(,"header")$endian
> [1] "little"
> How can I get only the numeric value, that ' -0.1346952' part?

The getVariable() function returns a named list where each element
contains the value of a particular Matlab object. You can request more
than one variable in each call. You need to use standard R list
operators to extract the element you'd like.  For example:

data <- getVariable(matlab, c("B", "A"));
B <- data$B;
A <- data$A;

Thus, instead of writing:

B <- getVariable(matlab, "B");
B <- B$B;

it is less confusing if you write:

data <- getVariable(matlab, "B");
B <- data$B;

/Henrik

>
>
> Thanks again,
>
> Michael
> On Fri, Aug 27, 2010 at 7:59 AM, michael <tufemichael at gmail.com> wrote:
>
>> Hi,all
>>                      I have a problem running R.matlab package
>> (under 2.10.1 version). I can set up the matlab server under local
>> machine(run the MatlabServer.m), "
>>
>>
>> And I can use setVariable and evaluate matlab functions in R. But when I
>> ask
>> Matlab to send the value back to R using getVariable function it
>> always returns an error:
>> "
>> ??? Error: A MATLAB string constant is not terminated properly.
>>
>> Error in ==> MatlabServer at 197
>>     eval(expr);
>> "
>>
>> it seems matlab have put the data into a temporary file, so my remote
>> option is actually FALSE? (how to set it to be true?), or otherwise
>> what could be the possible problem since I can send data to matlab
>> from R but not vice versa.
>>
>>
>>
>> > sessionInfo()
>> R version 2.10.1 (2009-12-14)
>> i386-pc-mingw32
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] R.utils_1.5.0     R.matlab_1.3.1    R.oo_1.7.3        R.methodsS3_1.2.0
>>
>>
>> > traceback()
>> 5: file(con, open = "rb")
>> 4: readMat.default(filename)
>> 3: readMat(filename)
>> 2: getVariable.Matlab(matlab, "B")
>> 1: getVariable(matlab, "B")
>>
>> Thanks,
>>
>> Michael
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list