Dear R-Experts,
here again a question concerning matlab. With the command "matrixM=[1 2
3;4 5 6]" a matrix under Matlab was constructed. It was than stored with
the command "save('matrixM.txt','matrixM')".
Now I tried to import the data in R with the help of the command
"Z=matrix(scan("Z:/Software/R-Programme/matrixM.txt"))"
An error occurred.
The result should be a matrix with the entries as mentioned above.
Perhaps I made already an error in matlab.
Has any one got an idea how to import the data and store it in R. In R I
want to make further calculations with the matrix. I just installed
R.matlab but could not find an example with could help me.
Thanks, Corinna
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: matrixM.txt
Url:
https://stat.ethz.ch/pipermail/r-help/attachments/20070410/2275f8ff/attachment.txt
I've used Henrik Bengtsson's R.matlab package several times to
successfully
read in matlab data files. It's normally as easy as:
library(R.matlab)
mats <- readMat("matrixM.txt")
- Tom
Tom Short
EPRI
Schmitt, Corinna wrote:>
> Dear R-Experts,
>
> here again a question concerning matlab. With the command "matrixM=[1
2
> 3;4 5 6]" a matrix under Matlab was constructed. It was than stored
with
> the command "save('matrixM.txt','matrixM')".
>
> Now I tried to import the data in R with the help of the command
> "Z=matrix(scan("Z:/Software/R-Programme/matrixM.txt"))"
>
> An error occurred.
>
> The result should be a matrix with the entries as mentioned above.
> Perhaps I made already an error in matlab.
>
> Has any one got an idea how to import the data and store it in R. In R I
> want to make further calculations with the matrix. I just installed
> R.matlab but could not find an example with could help me.
>
> Thanks, Corinna
>
> MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Tue Apr 10 13:17:44 2007
> ?IM???3???x??c``p?b6 ??? ?
> ?31331;?&?eV???AjY?X???[n|
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>
--
View this message in context:
http://www.nabble.com/Matlab-import-tf3552511.html#a9918327
Sent from the R help mailing list archive at Nabble.com.
Hello: Two questions about R.matlab: 1. How to break a hung R-Matlab connection? 2. How to execute R.matlab commands from within a function? BREAKING AN R-Matlab CONNECTION Sometimes an attempted R.matlab command locks up my computer. The standard R break process interrupts the R command. However, when I do that, the command to Matlab is still pending, and I don't know an easy way to interrupt that. A simple, self-contained example appears below. The easiest way I've found so far to interrupt Matlab is to quit R. This will finally release Matlab. CALLING R.matlab FUNCTIONS FROM WITHIN A FUNCTION An R.matlab function call that works as a direct R command hangs for me when executed within an R function. A simple, self-contained example appears below. How can I work around this? Thanks, Spencer Graves Using Matlab 7.3.0 (R2006b) under Windows XP Pro.> sessionInfo()R version 2.5.0 (2007-04-23) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] "splines" "stats" "graphics" "grDevices" "utils" "datasets" [7] "methods" "base" other attached packages: R.matlab R.oo fda zoo "1.1.3" "1.2.7" "1.2.1" "1.3-1" ################### #EXAMPLE: CALLING R.matlab FROM WITHIN A FUCTION? # 1. library(R.matlab) library(R.matlab) # 2. Create a Matlab client object to support communications (matlab <- Matlab()) # Optionally set setVerbose(..., -2) to get max info setVerbose(matlab, -2) # 3. Start Matlab # 4. Ask Matlab to become a slave #Matlab>> MatlabServer # 5. Open the connection from R to MatlabServer (isOpenMatlab <- open(matlab)) # NOTE: If Matlab is not frozen: #R> close(matlab) # returns local control to Matlab. # Control of Matlab can be returned to R at any time # by repeating steps 4 & 5. # 6. matlab.compute.a compute <- evaluate(matlab, "a = 1+2") (a0 <- getVariable(matlab, "a")) # The above works fine for me. # 7. R.matlab.compute.a function R.matlab.compute.a <- function(text="a=1+2", matlabClient=matlab){ # text = a Matlab expression that stores 'a' ev0 <- evaluate(matlabClient, text) getVariable(matlabClient, "a") } # The following locks up both R and Matlab for me: R.matlab.compute.a()