title: MATLAB Error : Invalid file identifier. Use fopen to generate a valid file identifier
body: <p>Hi I get the this error with the following script -</p>
  
  <p>The script :</p>
  
  <pre><code>fid = fopen('TR2.roi', 'r');
  
  test = []; % test variable for holding current line from text file
  while isempty(test)
  
      fline = fgetl(fid);
      disp('b');
      test = strmatch('; Number of',fline); 
  end
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Error using fgets
  Invalid file identifier.  Use fopen to generate a valid file identifier.
  
  Error in fgetl (line 36)
  [tline,lt] = fgets(fid);
  
  Error in test1 (line 6)
      fline = fgetl(fid);
  </code></pre>
  
  <p>Any solutions and reason why this error? I have verified my fid it is >2.</p>