title: How to combine vectors of different length in a cell array into matrix in MATLAB
body: <p>How to efficiently combined cell array vectors with different length into a matrix, filling the vectors to max length with 0s or NaNs? It would be a nice option for <code>cell2mat()</code>.</p>
  
  <p>For example, if I have</p>
  
  <pre><code>C = {1:3; 1:5; 1:4};
  </code></pre>
  
  <p>I'd like to get either</p>
  
  <pre><code>M = [1 2 3 0 0
       1 2 3 4 5
       1 2 3 4 0];
  </code></pre>
  
  <p>or</p>
  
  <pre><code>M = [1 2 3 NaN NaN
       1 2 3 4 5
       1 2 3 4 NaN];
  </code></pre>