如何在 MATLAB 中检查 MAT 文件的内容而不加载它?

发布于 2024-09-29 00:31:02 字数 267 浏览 0 评论 0原文

我的 MAT 文件中有一个大型结构。我想在不加载 MAT 文件的情况下检查结构中是否存在特定字段,因为内容非常大,并且我想最大限度地减少内存使用。

这是可能的,还是我必须像下面的示例一样先加载它?:

load('test.mat');             %# Load the MAT-file
tf = isfield(s,'fieldname');  %# Check if structure s has field 'fieldname'

I have a large structure in a MAT-file. I want to check if a specific field is present in the structure without loading the MAT-file since the contents are very large and I want to minimize memory use.

Is this possible, or must I load it first like in the following example?:

load('test.mat');             %# Load the MAT-file
tf = isfield(s,'fieldname');  %# Check if structure s has field 'fieldname'

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

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

发布评论

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

评论(2

找回味觉 2024-10-06 00:31:02

要检查 MAT 文件的内容而不加载它,请使用:

vars = whos('-file','test.mat')
ismember('fieldname', {vars.name})

To check the contents of a MAT file without loading it, use:

vars = whos('-file','test.mat')
ismember('fieldname', {vars.name})
夏尔 2024-10-06 00:31:02

据我所知,您必须加载文件才能检查保存的结构是否包含特定字段。

但是,如果您使用 '-struct' 保存 .mat 文件-option,它将字段拆分为 .mat 文件中的单独变量。您可以通过调用 Save 来重新创建结构,

myStructure = load('test.mat');

这种方式还允许您使用 @Amro 的方法(比我之前建议的要干净得多)。

As far as I know, you have to load the file in order to be able to check if a saved structure contains a specific field.

However, if you save the .mat file with the '-struct'-option, it splits the fields into separate variables in the .mat file. You can recreate the structure by calling

myStructure = load('test.mat');

Saving this way also allows you to test for whether a field (variable) exists by using @Amro's approach (which is a lot cleaner than what I suggested before).

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