title: Matlab read in txt file into array
body: <p>I have a text file with the following format of information:</p>
  
  <pre><code>Name1 34 25 36 46
  Name1 23 53 15 86
  Name1 25 25 87 35
  Name2 76 22 44 55
  Name2 88 88 88 88
  Name3 11 11 11 11
  Name3 55 66 88 88
  Name3 88 88 88 88
  Name3 00 00 00 00
  </code></pre>
  
  <p>There are different "Names" and I have to arrange each name into an array slot. I would then need another way to allocate the date associated with each row to that specific spot. So for example, the first Name1 may have array{0}, but I would also need to associate the 34, 24, 36, and 46 somehow. I would also need to distinguish the different names from each other. What is the best way to do this? a 2x2 array does not seem to be the solution.</p>
  
  <p>What I have so far is something along the lines of this:</p>
  
  <pre><code>%# read the whole file to a temporary cell array
  fid = fopen(filename,'rt');
  tmp = textscan(fid,'%s','Delimiter','\n');
  fclose(fid);
  
  %# remove the lines starting with headerline
  tmp = tmp{1};
  idx = cellfun(@(x) strcmp(x(1:10),'headerline'), tmp);
  tmp(idx) = [];
  
  %# split and concatenate the rest
  result = regexp(tmp,' ','split');
  result = cat(1,result{:});
  
  %# delete temporary array (if you want)
  clear tmp
  </code></pre>
  
  <p>Courtesy: <a href="https://stackoverflow.com/questions/9195716/read-txt-file-in-matlab">Read txt file in Matlab</a></p>
  
  <p>Could someone please tell me the best way to arrange the information? Thanks, help is much appreciated.</p>