Given a matrix A, that has zeros on its diagonal and its lower triangular part:
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
I want to convert A into a compact vector v that skips all the zero elements:
v = [0.47474 0.55853 0.30159 0.97474 0.03315
0.74577 0.20878 0.54966 0.76818 0.82598]
Later I want to convert from the vector back to the matrix.
Question: What is an elegant way to convert between these two representations?