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

Elpezmuerto picture Elpezmuerto · Oct 26, 2010 · Viewed 16.6k times · Source

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'

Answer

Amro picture Amro · Oct 26, 2010

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

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