title: MATLAB Find all files in folder with subfolders with extension .txt and read with textscan
body: <p>I want to find all files with extension .txt in a folder with sub folders. These sub folders contain .txt-files which I want to read using the textscan function.</p>
  
  <p>The .txt-files contain numbers and a header line:</p>
  
  <pre><code>A B C D
  1 0.4 23 42
  2 0.3 32 34
  </code></pre>
  
  <p>Here is what I tried. But I get always the error:</p>
  
  <pre><code>Error using fopen
  Invalid permission.
  </code></pre>
  
  <p>What do I wrong? I already tried to work with code I found in the internet but it does not work for my problem.</p>
  
  <pre><code>dirinfo = dir();
      dirinfo(~[dirinfo.isdir]) = [];  %remove non-directories
  
      subdirinfo = cell(length(dirinfo));
      for k = 1 : length(dirinfo)
          thisdir = dirinfo(k).name;
          subdirinfo{k} = dir(fullfile(thisdir, '*.txt'));
  
          for m=1:length(subdirinfo)
              for n=1:length(subdirinfo{m})
                  fileID = fopen(subdirinfo{m,n}.name);
                  C = textscan(fileID,'%f32 %f32 %f32 %f32','HeaderLines',1);
                  fclose(fileID);
                  % do stuff
              end
          end 
      end
  </code></pre>
  
  <p>Thank you for helping me!</p>