How can I check the contents of a MAT-file in MATLAB without loading it?

前端 未结 2 441
失恋的感觉
失恋的感觉 2021-02-07 19:44

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 a

相关标签:
2条回答
  • 2021-02-07 20:16

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

    0 讨论(0)
  • 2021-02-07 20:24

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

    vars = whos('-file','test.mat')
    ismember('fieldname', {vars.name})
    
    0 讨论(0)
提交回复
热议问题