Change values in matrix depending on the original value in the matrix