Implement matrix-to-vector