title: Matlab: Read in ascii with varying column numbers & different formats
body: <p>I have been working on a puzzling question that involves reading an ascii file into matlab that contains 2 parts of different formats, the first part also including different column numbers.</p>
  
  <pre><code>MESH2D
  MESHNAME "XXX"
  E3T 1 1 29 30 1
  E4Q 2 2 31 29 1 1
  E4Q 3 31 2 3 32 1
  ...
  ...
  ...
  ND 120450 5.28760039e+004 7.49260000e+004 8.05500000e+002
  ND 120451 5.30560039e+004 7.49260000e+004 6.84126709e+002
  ND 120452 5.32360039e+004 7.49260000e+004 6.97750000e+002
  ND 120453 5.34010039e+004 7.49110000e+004 7.67000000e+002
  NS  1 2 3 4 5 6 7 8 9 10
  NS  11 12 13 14 15 16 17 18 19 20
  NS  21 22 23 24 25 26 27 -28
  BEGPARAMDEF
  GM  "Mesh"
  </code></pre>
  
  <p>I am only interested in the lines that contain the triangles and start with E3T/E4Q and the corresponding lines that hold the coordinates of the nodes of the triangles and start with ND. For the triangles (E3T/E4Q lines) I am only interest in the first 4 numbers, therefore I was trying to do something like this:</p>
  
  <pre><code>fileID = fopen(test);
  t1 = textscan(fileID, '%s',3);
  t2 = textscan(fileID, '%s %d %d %d*[^\n]');
  fclose(fileID);
  </code></pre>
  
  <p>So read in the header to jump to the data and then read the first string and following 4 numbers, then jump to the end of the line and restart. But this does not work. I only get A single line with data and not the rest of the file. Also, I do not know how to treat the second part of the file, which starts at an arbitrary amount of numbers (which I could of course look up manually and feed into matlab, but would prefer matlab to find this change in format automatically).</p>
  
  <p>Do you have any suggestions?</p>
  
  <p>Cheers!</p>