我正在尝试使用 R.matlab 将 matlab 文件读入 R,但遇到此错误:
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.
如何解决这个问题或者是否有其他方法来加载 matlab 文件?我可以使用 hdf5load,但听说这会弄乱数据。谢谢!
最佳答案
回复有点晚了,但我最近遇到了同样的问题。对我来说,问题是我默认使用“-v7.3”选项保存 matlab 文件。经过大量搜索,R.matlab 源文档 ( http://cran.r-project.org/web/packages/R.matlab/R.matlab.pdf ) 指出以下内容:
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'."
在保存命令末尾添加“-v7”选项解决了此问题。 即:保存('文件名','变量','-v7')
关于R.matlab/readMat : Error in readTag(this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11318331/