Skip to content

[Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files

7 messages · Christian Gunning, Dale Smith, John Buonagurio +1 more

#
Can you provide a link to the mat.h file referenced in the source
(which I assume is the same as the API mentioned below)?

Also, see Dirk's comments about compilers here:
http://stackoverflow.com/questions/10723165/using-visual-c-with-r
and here:
dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf

Best,
Christian

  
    
#
mat.h is a header file which comes with MATLAB. I don't think the license allows redistribution, and you would not be able to compile without the MATLAB libraries.

An alternative may be Octave since it will read .mat files. Perhaps someone can email the name of the header file used from the Octave distribution?

http://stackoverflow.com/questions/9915658/how-do-you-open-mat-files-in-octave

This also offers a viable way to test this type of code for those who don't have MATLAB.

Dale Smith, Ph.D. | Data Scientist | nexidia | office: +1 404 495 7220 ext 4008 | fax: +1 404 495 7221 | nexidia.com


-----Original Message-----
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Christian Gunning
Sent: Wednesday, March 25, 2015 8:08 AM
To: rcpp-devel at lists.r-forge.r-project.org
Subject: [Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files

Can you provide a link to the mat.h file referenced in the source (which I assume is the same as the API mentioned below)?

Also, see Dirk's comments about compilers here:
http://stackoverflow.com/questions/10723165/using-visual-c-with-r
and here:
dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf

Best,
Christian
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal ? Panama!
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
#
Dale -

Thank you for the suggestion. I have MATLAB and the MATLAB libraries, and I
am not looking to redistribute anything. I just have a lot of data in MAT
files that I would like to be able to load analyze in R. I am able to
compile and link against the MATLAB libraries, but the code crashes when I
run it. I looked into the Octave FAQ. It looks like they don't handle v7.3
files either, and I don't think they provide an API that I could access
from R/C++.

- Elliot
On Wed, Mar 25, 2015 at 8:36 AM, Dale Smith <DSmith at nexidia.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150325/ef73bfbd/attachment.html>
#
Elliot,

How are you building the executable? Did you make sure to include all dependencies in the search path (run depends.exe against libmat.dll and libmx.dll)? Did you make sure to set the appropriate architecture e.g. -m64 in CFLAGS? I don't have access to the MAT-File libraries to test this myself.

Start simple and take Rcpp out of the equation. Call matOpen from a simple C function with type void. Does it work with dyn.load() and .C()?

If you are *only* working with v7.3 files which are based on HDF5, you may be able to avoid this issue and access them using rhdf5: 

source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
library(rhdf5)
h5dump("file.mat", load=FALSE)

John

From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Elliot Joel Bernstein
Sent: Wednesday, March 25, 2015 9:28 AM
To: Dale Smith
Cc: xian at unm.edu; rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files

Dale -

Thank you for the suggestion. I have MATLAB and the MATLAB libraries, and I am not looking to redistribute anything. I just have a lot of data in MAT files that I would like to be able to load analyze in R. I am able to compile and link against the MATLAB libraries, but the code crashes when I run it. I looked into the Octave FAQ. It looks like they don't handle v7.3 files either, and I don't think they provide an API that I could access from R/C++.

- Elliot
On Wed, Mar 25, 2015 at 8:36 AM, Dale Smith <DSmith at nexidia.com> wrote:
mat.h is a header file which comes with MATLAB. I don't think the license allows redistribution, and you would not be able to compile without the MATLAB libraries.

An alternative may be Octave since it will read .mat files. Perhaps someone can email the name of the header file used from the Octave distribution?

http://stackoverflow.com/questions/9915658/how-do-you-open-mat-files-in-octave

This also offers a viable way to test this type of code for those who don't have MATLAB.

Dale Smith, Ph.D. | Data Scientist | nexidia | office: +1 404 495 7220 ext 4008 | fax: +1 404 495 7221 | nexidia.com


-----Original Message-----
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Christian Gunning
Sent: Wednesday, March 25, 2015 8:08 AM
To: rcpp-devel at lists.r-forge.r-project.org
Subject: [Rcpp-devel] R.e. Using Rcpp and MATLAB MAT-File API to Read MAT Files

Can you provide a link to the mat.h file referenced in the source (which I assume is the same as the API mentioned below)?

Also, see Dirk's comments about compilers here:
http://stackoverflow.com/questions/10723165/using-visual-c-with-r
and here:
dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf

Best,
Christian
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal ? Panama!
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
#
John -

Thanks for the suggestions. I tried taking not only Rcpp but R out of the
loop, and just compiling from the command line with MinGW. That crashed as
well, so I think there's probably a compatibility issue with MATLAB's API
and MinGW. I'll contact Mathworks tech support to try and get some help
with that.

Regarding v7.3...my files aren't all v7.3, but I could definitely save them
all that way, which might be the easiest solution. I tried what you
suggested with some of my real data files, which contain two variables
each: a matrix and a struct. I get the following warnings:
Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced
by NA's
Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced
by NA's
Warning: h5read for type 'REFERENCE' not yet implemented. Values replaced
by NA's

The data look OK, as far as I can tell. (The matrix is 411x30927, so it's
not like I can check every element, but I don't see anything obviously
wrong.) In addition to the two variables I was expecting, the result has
two additional elements, #refs# and #subsystem. I'm not actually sure how
to see what they contain, since the names include the comment character.
Can I safely ignore those warnings?

Thanks.

- Elliot


On Wed, Mar 25, 2015 at 11:09 AM, John Buonagurio <jbuonagurio at exponent.com>
wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150325/2dd85070/attachment-0001.html>
#
John -

One quick follow-up about the warnings: I think they have to do with
loading cell arrays. Basically, all the actual data ends up in the #refs#
field, in what seems like an arbitrary order, and the field that should
contain the data is all NAs. Do you know if there's any way to get around
that? I think all the cell arrays being saved contain only strings, so I
can change things in MATLAB to save them as char arrays if necessary.

Thanks.

- Elliot

On Wed, Mar 25, 2015 at 12:26 PM, Elliot Joel Bernstein <ejb6 at cornell.edu>
wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150325/1e3e67d5/attachment.html>
#
It turns out this wasn't really a Rcpp issue, but I want to post the
solution, in case someone stumbles on this thread while trying to use the
MAT-file API with MinGW. It turns out I was just linking against the wrong
libraries. My original library directory was
C:/MATLAB2013a/extern/lib/win64/microsoft,
but the correct one is C:/MATLAB2013a/bin/win64. (Where "C:/MATLAB2013a"
should be replaced by the root of your MATLAB installation.)

- Elliot

On Wed, Mar 25, 2015 at 12:57 PM, Elliot Joel Bernstein <ejb6 at cornell.edu>
wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150326/b8ccafe1/attachment.html>