title: Changing representations: Upper triangular matrix and compact vector (Octave / Matlab)
body: <p>Given a matrix <strong>A</strong>, that has zeros on its diagonal and its lower triangular part:</p>
  
  <pre><code>A = triu(rand(5,5), 1) % example
  
  A =
  0.00000   0.47474   0.55853   0.30159   0.97474
  0.00000   0.00000   0.03315   0.74577   0.20878
  0.00000   0.00000   0.00000   0.54966   0.76818
  0.00000   0.00000   0.00000   0.00000   0.82598
  0.00000   0.00000   0.00000   0.00000   0.00000
  </code></pre>
  
  <p>I want to convert <strong>A</strong> into a compact vector <strong>v</strong> that skips all the zero elements:</p>
  
  <pre><code>v = [0.47474 0.55853 0.30159 0.97474 0.03315
       0.74577 0.20878 0.54966 0.76818 0.82598]
  </code></pre>
  
  <p>Later I want to convert from the vector back to the matrix. </p>
  
  <p><em><strong>Question: What is an elegant way to convert between these two representations?</em></strong></p>