Converts a matrix to a set.