title: Fast way to check if variable is in .mat file without loading .mat file? 'who'/'whos' is not faster than loading.. Better options than 'who'?
body: <p>I have a .mat file named "myfile.mat" that contains a huge varible <code>data</code> and, in some cases, another variable <code>data_info</code>.   What is the fastest way to check if that .mat file contains the `data_info' variable?</p>
  
  <p>the who or whos commands are not faster than simply loading and testing for the existens of varible.</p>
  
  <pre><code>nRuns=10;
  %simply loading the complete file
  tic
  for p=1:nRuns
      load('myfile.mat');
      % do something with variable
      if exist('data_info','var')
          %do something
      end
  end
  toc
  
  % check with who
  tic
  for p=1:nRuns
     variables=who('-file','myfile.mat');
     if ismember('data_info', variables)
         % do something
     end
  end
  toc
  
  % check with whose
  tic
  for p=1:nRuns
     info=whos('-file','myfile.mat');
     if ismember('data_info', {info.name})
         %do something
     end
  end
  toc
  </code></pre>
  
  <p>All methods roughly take the same time (which is way to slow, since <code>data</code> is huge.</p>
  
  <p>However, this is very fast:</p>
  
  <pre><code>tic
  for p=1:nRuns
      load('myfile.mat','data_info');
      if exist('data_info', 'var')
          %do something
      end
  end
  toc
  </code></pre>
  
  <p>But it issues a warning, if <code>data_info</code> does not exist. I could suppress the warning, but that doesn't seem like the best way to do this..  What other options are there?</p>
  
  <p><strong>Edit</strong>
  using <code>who('-file', 'myfile.mat', 'data_info')</code>  is also not faster:</p>
  
  <pre><code>tic
  for p=1:nRuns
      if ~isempty(who('-file', 'myfile.mat', 'data_info'))
        % do something
      end
  end
  toc    % this takes 7 seconds, roughly the same like simply loading complete .mat file
  </code></pre>