title: Reading a .dat file into MATLAB variables
body: <p>I've used neworkx to generate a random geometric graph on 50 nodes, and create a .dat file with some attributes of this network. </p>
  
  <p>I need to access these as MATLAB variables. I read the file in as a data string using:</p>
  
  <pre><code>fid = fopen('mydata.dat','r')
  data = textscan(fid, '%s')
  fclose(fid)
  </code></pre>
  
  <p>The structure of the data file is as follows</p>
  
  <pre><code>conn = val
  Adj = val ..... val
        .............
        val ......val
  pos = 
  [0.7910629988376467, 0.5523474928588686]
  ...
  [0.6799716933198028, 0.6981655240935597]
  </code></pre>
  
  <p>i.e. conn is a number, Adj is (supposed to be) a 50 by 50 matrix and pos is a 50 by 2 matrix.</p>
  
  <p>I can read conn, and Adj as MATLAB variables fine, but I'm having trouble reading pos. The first instance starts at data{1}{2508}, and is </p>
  
  <pre><code>data{1}{2508} 
  &gt;&gt;&gt; [0.7832623541518583,
  </code></pre>
  
  <p>How do I shoehorn this into a 50 by 2 (or 2 by 50) matrix?</p>
  
  <p>To read the Adj I use</p>
  
  <pre><code>P = 50 %number of nodes
  index = 5
  
  for i=1:P
      for j = 1:P
          Adj(i,j) = str2double(data{1}(index + P*(i-1) +j))
      end
  end
  </code></pre>
  
  <p>I thought something similar would work for pos, but with <code>j = 1:2</code> and <code>index = 2508</code> but I'm getting NaNs as the lines (fields?) of my .dat file aren't just values, they're of the form <code>[val,</code> or <code>,val]</code> </p>