title: MATLAB: 2-D array of structs (containing vectors) to 3-D Array?
body: <p>I have a 2-dimensional array of structs 'cell' which each contain a number of vectors:</p>
  
  <pre><code>cell(1,1).U = [1 2 3];
  cell(1,2).U = [4 5 6];
  cell(2,1).U = [7 8 9];
  cell(2,2).U = [0 1 2];
  </code></pre>
  
  <p>I would like to extract the data into a 3-D array A(i,j,k).</p>
  
  <p>Using cell-style extraction returns a 1x3 cell, the contents of which are</p>
  
  <pre><code>&gt;&gt; {cell.U}
  ans = {[cell(1,1).U]   [cell(1,2).U]   [cell(2,1).U]   [cell(2,2).U]}
  </code></pre>
  
  <p>And thus, converting this to a matrix using cell2mat(), as in:</p>
  
  <pre><code>cell2mat(ans)
  </code></pre>
  
  <p>Returns a 3x4 array.</p>
  
  <p>Ideally, I would like a 2x2x3 array so that the indices i and j are preserved. Is there any way (short of looping) to accomplish this?</p>