As others have said, you do not necessarily want to verify exact equality with the identity matrix. In addition, using eye can potentially consume unnecessary memory for large enough matrices. I would recommend using diag to get around this.
isdiag(a) && all(abs(diag(a) - 1) < tolerance)
Suver source share