Converts a matrix to a string.