Search code examples
rmatlaberror-handling

Reading a .mat file using R


I'm trying to read a .mat file using R.

library(R.matlab)
data <- readMat('e-060RAW.mat')

It gives me this error.

Error in readMat5(con, firstFourBytes = firstFourBytes, maxLength = maxLength) : 
  Reading of MAT v7.3 files is not supported. If possible, save the data in MATLAB using 'save -V6'.

How am I supposed to get this sorted out. Is there any other way to read a .mat file using R.


Solution

  • From https://www.rdocumentation.org/packages/R.matlab/versions/3.6.2/topics/readMat:

    MAT v7.3 files, saved using for instance save('foo.mat', '-v7.3'), stores the data in the Hierarchical Data Format (HDF5) [6, 7], which is a format not supported by this function/package. However, there exist other R packages that can parse HDF5, e.g. CRAN package h5 and Bioconductor package rhdf5.