Reshaping functions: Vec(), Vecdiag(), Diag(), and Shape()

These functions reshape matrices. Vec() sends a matrix to a vector. The columns of the vector are stacked into a rcx1 vector. Vecdiag() extracts the principal diagonal of a square matrix into a vector. Diag() sends a vector into the principal diagonal of a square zero matrix. It also zeros the off-diagonal elements if the input matrix is square.

Shape() takes an rxc matrix to a new matrix with nrows rows. The value of nrows must divide rc without a remainder or the program will stop.