change matrix to vector. intermediate step