title: Save loop results
body: <p>I have a simple question but I don't know how to solve it. </p>
  
  <p>I want to process all the files in a folder and I want to write the output values on a separate line on a matrix. After direct the folder and get the list of the files and their names</p>
  
  <pre><code>filePattern=fullfile( myPath,'*.txt') 
  </code></pre>
  
  <p>I applied a 'loop'. To save the results on each line for every file, this is what I'm doing but it doesn't work (the code works with one file, not with all of them). </p>
  
  <pre><code>text= {baseFileName, result2b, result3b, result4b, result5b};
  </code></pre>
  
  <p>Is there something wrong? </p>
  
  <p>Thanks in advance! Greetings, </p>
  
  <p>Emma</p>
  
  <p>PD)</p>
  
  <pre><code>myPath = 'C:\SP\';
  % if ~isdir(myPath)
  %   errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
  %   uiwait(warndlg(errorMessage));
  %   return;
  
  
  
      a= dir (fullfile(myPath,'*.DIM')); % 
      fileNames = { a.name };
  
   filePattern=fullfile( myPath,'*.txt');
   txtFiles= dir(filePattern);    
     for k = 1:length(txtFiles)
      baseFileName=txtFiles(k).name;
      fullFileName= fullfile(myPath,baseFileName);
  
  fid=fopen(fullFileName, 'r+');
      for i = 1:18
      m{i} = fgetl(fid);
      end
       result2 = m{18};
       result2b= result2([12:19]);
  
  (...)
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I added a screenshoot about my variables. Is it possible because of the txtFiles is wrong?</p>
  
  <p><img src="https://i.stack.imgur.com/pFRT3.jpg" alt="enter image description here"></p>