[R] readMat - how to retrieve the variables
David Winsemius
dwinsemius at comcast.net
Mon Mar 14 00:36:39 CET 2011
On Mar 13, 2011, at 7:27 PM, Eduardo M. A. M.Mendes wrote:
> Hello there
>
> Here is the output of the command
>
> structure(list(a =
> structure(list(structure(list(structure(c(16.259746877453,
> 17.7125316239611, 17.7801266531401, 18.7370886410339,
> 18.5622784910323,
> 19. ....
That seems pretty unlikely. All of those "...." are not in the output
from dput are they? The dimension of 3683 implies otherwise.
> ....
> ), .Dim = c(3683L, 1L)), structure(c(0, 0, 6.7, 46.1, 2, 0, 29.5,
> 93.7, 4.5, 39.6, 1.4, 5.5, 9, 12.2, 5.7, 0, 0, 0, 0, 8, 0, 19.5,
> 30 ....
> ....
> ), .Dim = c(3683L, 1L))), .Dim = c(2L, 1L, 1L), .Dimnames = list(
> c("flow", "precip"), NULL, NULL)), structure(list(structure(c(42,
> 42, 44, 60, 84, 97, 113, 357, 613, 495, 401, 295, 250, 228, 202,
> 174 ....
> ....
> 12, 36, 0, 2, 0, 6, 13, 0, 1, 0, 12, 0, 0, 32, 0, 0, 1, 36, 7,
> 36, 48, 27, 7), .Dim = c(3683L, 1L))), .Dim = c(2L, 1L,
> 1L), .Dimnames =
> list(
> c("flow", "precip"), NULL, NULL))), .Dim = c(2L, 1L,
> 1L), .Dimnames =
> list(
> c("river1", "river2"), NULL, NULL))), .Names = "a", header =
> structure(list(
> description = "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on:
> Sun Mar
> 13 18:51:54 2011 ",
> version = "5", endian = "little"), .Names = c("description",
> "version", "endian")))
>
> Cheers
>
> Ed
>
>
> -----Original Message-----
> From: David Winsemius [mailto:dwinsemius at comcast.net]
> Sent: Sunday, March 13, 2011 8:01 PM
> To: Eduardo M. A. M.Mendes
> Cc: 'Joshua Wiley'; R-help at r-project.org
> Subject: Re: [R] readMat - how to retrieve the variables
>
>
> On Mar 13, 2011, at 6:42 PM, Eduardo M. A. M.Mendes wrote:
>
>>
>> Hi Joshua
>>
>> Many thanks.
>>
>> The values of flow can be accessed in a weird way and we can used
>> them
>> for some calculations. Since I am a newbie as far as using R is
>> concerned I wonder whether you could tell me how to create a
>> structure
>> in R that looks like the one I have in matlab (that is, a variable a
>> that contains river1 and river2 that contains flow and
>> precipitation).
>
> If you posted the results of dput(a) , we might be able to test our
> pet
> theories, but here is my hapless first guess:
>
> mat.R.struc <- with(b$a[,,1], #looks like it was a matrix that had
> lists as elements
> cbind(as.data.frame(river1), as.data.frame(river2) )
> )
>
> It's not so much that it will "look like" your Matlab structure, but
> it
> could be something that you can work with. This will create a long-
> format
> structure which is a typical one for plotting ans regression.
> Another option would be an R array which, unlike matrices, can have
> more
> than 2 dimensions.
>
>
>>
>> Cheers
>>
>> Ed
>>
>>
>> -----Original Message-----
>> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
>> Sent: Sunday, March 13, 2011 7:20 PM
>> To: Eduardo M. A. M.Mendes
>> Cc: R-help at r-project.org
>> Subject: Re: [R] readMat - how to retrieve the variables
>>
>> On Sun, Mar 13, 2011 at 2:56 PM, Eduardo M. A. M.Mendes
>> <emammendes at gmail.com
>>> wrote:
>>> Hi Joshua
>>>
>>> Many thanks for the prompt reply.
>>>
>>> I have saved a short version of the matlab file and the output on R
>>> is
>>>
>>>> b=readMat("testr.mat")
>>>> b
>>> $a
>>> , , 1
>>>
>>> [,1]
>>> river1 List,2
>>> river2 List,2
>>
>> It looks like you are dealing with a special series of lists nested
>> within three dimensional arrays within lists. My suggestion would be
>> to double check that the matlab file has reasonable data (whatever
>> that means) and try to double check your use of readmat (do you meet
>> all the requirements for versions, etc.). That is not
>> a common R structure so the extraction is similarly uncommon.
>> Perhaps Henrik will be along with more helpful answers.
>>
>> Good luck,
>>
>> Josh
>>>
>>>
>>> attr(,"header")
>>> attr(,"header")$description
>>> [1] "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Sun Mar 13
>>> 18:51:54 2011 "
>>>
>>> attr(,"header")$version
>>> [1] "5"
>>>
>>> attr(,"header")$endian
>>> [1] "little"
>>>
>>> When I issue the command b$a[,,1]$river1[,,1]$flow I see the flow
>>> values.
>>>
>>> Unfortunately the data is confidential.
>>>
>>> Many thanks
>>>
>>> Ed
>>>
>>>
>>> -----Original Message-----
>>> From: Joshua Wiley [mailto:jwiley.psych at gmail.com]
>>> Sent: Sunday, March 13, 2011 6:30 PM
>>> To: Eduardo M. A. M.Mendes
>>> Cc: R-help at r-project.org
>>> Subject: Re: [R] readMat - how to retrieve the variables
>>>
>>> Hi Ed,
>>>
>>> Can you please provide *at least* the R output from running:
>>>
>>> str(data)
>>>
>>> where "data" is the variable name you stored the results of
>>> readMat() in. If it is reasonably small and can be sent as
>>> plaintext
>>> (I do not know Matlabs file format off hand), you could send us the
>>> actual data so we can try to read it in, but at the least str() will
>>> let us see how R is storing your data and give you some explanation.
>>>
>>> Side note, as data() is a function, it might be worthwhile to call
>>> your actual data something else (say, mydata, dat, etc.). For
>>> anyone
>>> else interested, readMat() is in package "R.matlab".
>>>
>>> Cheers,
>>>
>>> Josh
>>>
>>> On Sun, Mar 13, 2011 at 2:07 PM, Eduardo M. A. M.Mendes
>>> <emammendes at gmail.com
>>>> wrote:
>>>> Hello
>>>>
>>>> I have a matlab MAT file that contains one single variable: a. The
>>>> structure of a is as follows:
>>>>
>>>> a.river1.flow (flow values)
>>>> a.river1.date_flow (date)
>>>> a.river1.precip (precipitation values) a.river1.date_precip
>>>> a.river2.flow a.river2.date_flow a.river2.precip
>>>> a.river2.date_precip
>>>>
>>>> I have used readMat to load the variable a in R, however I have no
>>>> idea how readMat translates a. I managed to get some values out of
>>>> data=readMat("matfile.mat")
>>>>
>>>> data$a[,,1]$river1[,,1]$flow -> Why do I need [,,1]? Why not
>>>> data$a$river1$flow?
>>>>
>>>> Many thanks
>>>>
>>>> Ed
>>>>
>>>> ______________________________________________
>>>> 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.
>>
>> --
>> Joshua Wiley
>> Ph.D. Student, Health Psychology
>> University of California, Los Angeles
>> http://www.joshuawiley.com/
>>
>> ______________________________________________
>> 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.
>
> David Winsemius, MD
> West Hartford, CT
>
>
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list