title: Reading a text file with multiple delimiters and matrices of different lengths
body: <p>I'm trying to read text files that contain multiple arrays of different (but known) sizes.</p>
  
  <p>I know the following about the files:</p>
  
  <p>Each file has a matrix of size m x n, in the format as in this example:</p>
  
  <pre><code>[[0.05,0.15,0.25,0.35,0.0]
  [0.05,0.1,0.15,0.2,0.25],
  [0.05,0.1,0.15,0.2,0.25],
  [0.05,0.1,0.5,0.6,0.1]]
  </code></pre>
  
  <p>This is followed by a matrix of size p x 1:</p>
  
  <pre><code>[3,3,4,5,5,5,5,6]
  </code></pre>
  
  <p>And finally a scalar (no square brackets here)   </p>
  
  <pre><code>3
  </code></pre>
  
  <p>The simplest way I've found to do this is the following: </p>
  
  <ol>
  <li>strip the brackets from the text files (using a language more appropriate than MATLAB!)</li>
  <li>Use <code>data = importdata()</code> to read the file. This results in one array, with the last two rows containing the p x 1 matrix and the scalar (with some NaNs because of the difference between matrix sizes)</li>
  <li>Pull out the data, <code>A = data(1:m, 1:n); b = data(m+1,1:p); c = data(m+2,1);</code></li>
  </ol>
  
  <p>This seems quite clunky. I can copy and paste the 2-dimensional matrix (with brackets included) into the MATLAB command window, and MATLAB knows how to parse it. This makes me think there is a more elegant way to do this with one MATLAB function.</p>
  
  <p>The whole example text file:</p>
  
  <pre><code>[[0.05,0.15,0.25,0.35,0.0],
  [0.05,0.1,0.15,0.2,0.25],
  [0.05,0.1,0.15,0.2,0.25],
  [0.05,0.1,0.5,0.6,0.1]]
  [3,3,4,5,5,5,5,6]
  3
  </code></pre>