title: MATLAB - loading data from file using file name stored as string variable
body: <p>I need to load data from file whose file names are enh0.dat, enh1.dat, enh2.dat, ..., up to 128 times. So I need to store the file name in a string variable and load data from a file, whose name is stored in the string variable, then store the loaded data in a specified variable for plotting later. But the MATLAB <code>load</code> command loads the data into a variable with a specific name (name of the file containing the data) which does not allow me to automate the use of plot command.</p>
  
  <p>Is it possible to store the name of the file from which I need to load data, in a string variable? I also checked out this
  <a href="https://stackoverflow.com/questions/6484942/matlab-newbie-problem-reading-in-file-when-the-file-name-is-stored-in-a-string">MATLAB newbie: problem reading in file when the file name is stored in a string</a>, but it doesn't look like it works for me. I get this error when trying to plot the result of <code>textscan</code>:</p>
  
  <blockquote>
    <p>??? Error using ==> plot Conversion to double from cell is not possible.</p>
  </blockquote>
  
  <p>This is the code used:</p>
  
  <pre><code>indx = [1:128];
  enh_file_cntr = 0;
  enh_pre = 'enh';
  gain_pre = 'gain';
  [enh_file_cntr_str, errmsg1] = sprintf('%d', enh_file_cntr);
  enh_file_name = strcat('enh', enh_file_cntr_str, '.dat');
  [gain_file_cntr_str, errmsg1] = sprintf('%d', enh_file_cntr);
  gain_file_name = strcat('enh', gain_file_cntr_str, '.dat');
  fid_enh = fopen(enh_file_name, 'r');
  fid_gain = fopen(gain_file_name, 'r');
  enh_data = textscan(fid_enh, '%f', 128);
  gain_data = textscan(fid_gain, '%f', 128);
  subplot(2,3,1);
  plot(indx, enh_data, 'b', indx, gain_data, 'r');
  </code></pre>
  
  <p>If this works I will be incrementing the value of <code>enh_file_cntr</code> in a <code>for</code> loop. How can I fix the above code?</p>