如何在 MATLAB 中检查 MAT 文件的内容而不加载它?
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要检查 MAT 文件的内容而不加载它,请使用:
To check the contents of a MAT file without loading it, use:
据我所知,您必须加载文件才能检查保存的结构是否包含特定字段。
但是,如果您使用
'-struct' 保存 .mat 文件
-option,它将字段拆分为 .mat 文件中的单独变量。您可以通过调用 Save 来重新创建结构,这种方式还允许您使用 @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 callingSaving 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).