R.matlab/readMat : Error in readTag(this)

标签 r

我正在尝试使用 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/

相关文章:

r - 如何通过另一个矩阵的值过滤矩阵

r - 如何使用 Dplyr 的 Summarize 和 which() 来查找最小值/最大值

r 生成带有随机 1 和 0 且有限制的列

r - 计算 R 中数据框中每对分类单元之间的差异性

Regex Tidyverse,如何捕获表达式(如果存在)

r - 如何使用 stat_contour 完全填充轮廓

r - 将 Shiny 的图缩放到窗口高度

r - 使用矩阵变量制作 "tidy"tibble 数据集

r - 如何在 docker 中加速 R 包的安装

r - 在 R 中转换数据