How can I create a condition on a matrix?