title: How to read numbered sequence of .dat files into MATLAB
body: <p>I am trying to load a numbered sequence of ".dat" named in the form a01.dat, a02.dat... a51.dat into MATLAB. I used the eval() function with the code below.</p>
  
  <pre><code>%% To load each ".dat" file for the 51 attributes to an array.
  
  a = dir('*.dat');
  
  for i = 1:length(a)
  eval(['load ' a(i).name ' -ascii']);
  end
  
  attributes = length(a);
  </code></pre>
  
  <p>I ran into problems with that as I could not easily manipulate the data loaded with the eval function. And I found out the community is strongly against using eval. I used the csvread() with the code below.</p>
  
  <pre><code>% Scan folder for number of ".dat" files
  datfiles = dir('*.dat'); 
  
  % Count Number of ".dat" files
  numfiles = length(datfiles); 
  
  % Read files in to MATLAB
  for i = 1:1:numfiles
      A{i} = csvread(datfiles(i).name);
  end
  </code></pre>
  
  <p>The csvread() works for me but it reads the files but messes up the order when it reads the files. It reads a01.dat first and then a10.dat and a11.dat and so on instead of a01.dat, a02.dat... The contents of each files are signed numbers. Some are comma-delimited and single column and this is an even split. So a01.dat's contents are comma-delimited and a02.dat's content are in a single column.</p>
  
  <p>Please how do I handle this?</p>