Reputation: 195
I am trying to read a matlab file into R using R.matlab but am encountering this error:
require(R.matlab)
r <- readMat("file.mat", verbose=T)
Trying to read MAT v5 file stream...
Error in readTag(this) : Unknown data type. Not in range [1,19]: 18569
In addition: Warning message:
In readMat5Header(this, firstFourBytes = firstFourBytes) :
Unknown MAT version tag: 512. Will assume version 5.
How can this issue be solved or is there an alternative way to load matlab files? I can use hdf5load but have heard this can mess with the data. Thanks!
Upvotes: 2
Views: 2523
Reputation: 21
This is a bit late on the response, but I've recently been running into the same issues. For me, the issue was that I was saving matlab files by default using the '-v7.3' option. After extensive searching, the R.matlab source documentation (http://cran.r-project.org/web/packages/R.matlab/R.matlab.pdf) indicates the following:
Reading compressed MAT files
From MATLAB v7, compressed MAT version 5 files are used by default [3,4]. This function supports reading such files, if running R v2.10.0 or newer. For older versions of R, the Rcompression package is used. To install that package, please see instructions at http://www.omegahat.org/ cranRepository.html. As a last resort, use save -V6 in MATLAB to write MAT files that are compatible with MATLAB v6, that is, to write non-compressed MAT version 5 files.
About MAT files saved in MATLAB using ’-v7.3’
This function does not support MAT files saved in MATLAB as save('foo.mat', '-v7.3'). Such MAT files are of a completely different file format [5,6] compared to those saved with, say, '-v7'."
adding the '-v7' option at the end of my save command fixed this issue. i.e.: save('filename', 'variable', '-v7')
Upvotes: 2
Reputation: 1
i had a very similar problem until i pointed the function to an actual .mat file that existed. before that i'd been specifying two files of the same name, but one was .mat and the other was .txt, so it may have been trying to open the other.
i realize this may not directly solve your issue (the only difference i saw in my error message was the absence of that first line "Trying ..." and the specific numbers thereafter as well as the presence of another couple similar warnings with odd numbers), but it might point to some simple filename problem as the issue.
i use the latest matlab on 64 bit vista and the latest R on 32 bit xp.
Upvotes: 0