convert matrix to 1D array