R:帮助将特定的 .mat 文件读入 R

发布于 2024-12-13 07:45:20 字数 625 浏览 5 评论 0原文

所以我一直在尝试将这个特定的.mat文件读入R。我对matlab了解不多,但我知道R.matlab包只能将未压缩的数据读入R,并将其保存为未压缩的我需要通过使用将其保存在 matlab 中 保存 new.mat -v6

好的,我就这样做了,但是当我在 R 中使用 readMat("new.mat") 时,它就永远卡在加载中了。我还尝试通过以下方式使用 hdf5 包:

> hdf5load("new.mat", load=FALSE)->g
Error in hdf5load("new.mat", load = FALSE) : 
  can't handle hdf type 201331051

我不确定这个问题可能是什么,但如果有人想尝试解决这个问题,该文件位于 http://dibernardo.tigem.it/MANTRA/MANTRA_online/Matlab_Code%26Data.html 并称为 inventory.mat (第一个文件)。

感谢您的帮助!

So I've been trying to read this particular .mat file into R. I don't know too much about matlab, but I know enough that the R.matlab package can only read uncompressed data into R, and to save it as uncompressed I need to save it as such in matlab by using
save new.mat -v6.

Okay, so I did that, but when I used readMat("new.mat") in R, it just got stuck loading that forever. I also tried using package hdf5 via:

> hdf5load("new.mat", load=FALSE)->g
Error in hdf5load("new.mat", load = FALSE) : 
  can't handle hdf type 201331051

I'm not sure what this problem could be, but if anyone wants to try to figure this out the file is located at http://dibernardo.tigem.it/MANTRA/MANTRA_online/Matlab_Code%26Data.html and is called inventory.mat (the first file).

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2024-12-20 07:45:20

这个特定的文件有一个对象,inventory,它是一个struct对象,里面有很多不同的东西。有些是元胞数组,其他是双精度数或逻辑向量,还有一些是双精度数矩阵。看起来 R.matlab 不喜欢结构中的单元格数组,但我不确定是什么导致 R 加载它出现问题。出于这样的原因,我通常建议避免将 Matlab 中的结构映射到 R 中的对象。它类似于列表,并且可以将其转换为列表,但这并不总是一个好主意。

我建议创建一个新文件,每个对象一个,例如 ids = inventory.instance_ids 并将每个对象保存到单独的 .mat 文件中,或者将所有对象(库存对象除外)保存到1 个文件。更好的是转到文本,例如通过 csvwrite,以便您可以看到正在创建的内容。

我意识到这是围绕使用 Matlab to R 阅读器进行的,但是采用通用、通用格式的内容对于再现性比获取一堆不同的专有格式阅读器更有用。

或者,您可以通过 R.matlab 或 此集合传递内存中的对象功能 + R/DCOM 接口(在 Windows 上)。

虽然这没有解决如何使用 R.matlab,但我已经在 R 和 Matlab 之间双向传输了大量数据,并且我发现最好避免使用 .mat 文件(同样,也避免使用 .rdat文件)。我喜欢在内存中传递对象,以便我可以在每一侧或通过标准文本文件检查它们。处理特定于应用程序的文件格式,尤其是那些变化很大且效率低下的文件格式(我正在看你的 MathWorks),并不是很好地利用时间。我很欣赏那些从事阅读器工作的人,但是对目标语言中使用的数据结构有更多的控制是非常值得使用简单的输出文件格式的空间开销的。内存中的数据传输非常好,因为您可以连接程序,但如果您的唯一目标是移动数据,这可能会分散您的注意力。

This particular file has one object, inventory, which is a struct object, with a lot of different things inside of it. Some are cell arrays, others are vectors of doubles or logicals, and a couple are matrices of doubles. It looks like R.matlab does not like cells arrays within structs, but I'm not sure what's causing issues for R to load this. For reasons like this, I'd generally recommend avoiding mapping structs in Matlab to objects in R. It is similar to a list, and this one can be transformed to a list, but it's not always a good idea.

I recommend creating a new file, one for each object, e.g. ids = inventory.instance_ids and save each object to either a separate .mat file, or save all of them, except for the inventory object, into 1 file. Even better is to go to text, e.g via csvwrite, so that you can see what's being created.

I realize that's going around use of a Matlab to R reader, but having things in a common, universal format is much more useful for reproducibility than to acquire a bunch of different readers for a proprietary format.

Alternatively, you can pass objects in memory via R.matlab, or this set of functions + the R/DCOM interface (on Windows).

Although this doesn't address how to use R.matlab, I've done a lot of transferring of data between R and Matlab, in both directions, and I find that it's best to avoid .mat files (and, similarly, .rdat files). I like to pass objects in memory, so that I can inspect them on each side, or via standard text files. Dealing with application specific file formats, especially those that change quite a bit and are inefficient (I'm looking at you MathWorks), is not a good use of time. I appreciate the folks who work on readers, but having a lot more control over the data structures used in the target language is very much worth the space overhead of using a simple output file format. In-memory data transfer is very nice because you can interface programs, but that may be a distraction if your only goal is to move data.

神爱温柔 2024-12-20 07:45:20

您是否运行了 http://cran.r 中的示例-project.org/web/packages/R.matlab/R.matlab.pdf 第 22 至 24 页?这将测试您读取版本 4 和 5 的能力。我不确定 R 是否无法读取压缩文件。 Omegahat 中有一个 Rcompression 包。

Have you run the examples in http://cran.r-project.org/web/packages/R.matlab/R.matlab.pdf on pages 22 to 24? That will test your ability to read from versions 4 and 5. I'm not sure that R cannot read compressed files. There is an Rcompresssion package in Omegahat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文