使用R读取.mat文件



我正在尝试使用R.读取.mat文件

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

它给了我这个错误。

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'.

我该如何解决这个问题。有没有其他方法可以使用R.读取.mat文件

来源https://www.rdocumentation.org/packages/R.matlab/versions/3.6.2/topics/readMat:

MAT v7.3文件,使用例如save('foo.mat', '-v7.3')保存,以分层数据格式(HDF5([6,7]存储数据是此函数/包不支持的格式。然而存在可以解析HDF5的其他R包,例如CRAN包h5和生物导体包装rhdf5。

使用hdf5r软件包读取.mat(V7.3,matlab>=2006b(文件

## install.packages("hdf5r")
library(hdf5r)
## ######################################################################
## create an hdf5 file
test_file <- tempfile(fileext=".h5")
file.h5 <- H5File$new( test_file, mode="w")
data(cars)
cars
file.h5$create_group("test")
file.h5[["test/cars"]] <- cars
cars_ds <- file.h5[["test/cars"]]
cars_ds
h5attr(cars_ds, "rownames") <- rownames(cars)
## Close the file at the end
## the 'close' method closes only the file-id, but leaves object inside the file open
## This may prevent re-opening of the file. 'close_all' closes the file and all objects in it
file.h5$close_all()
## read and investigate the hdf5 file
file.h5 <- H5File$new(test_file, mode="r+")
## lets look at the content
file.h5$ls(recursive=TRUE)
cars_ds <- file.h5[["test/cars"]]
## note that for now tables in HDF5 are 1-dimensional, not 2-dimensional
mycars <- cars_ds[]
h5attr_names(cars_ds)
h5attr(cars_ds, "rownames")
file.h5$close_all()

相关内容

  • 没有找到相关文章

最新更新