 <p>Adding to Ansari's answer, the <code>diagDominantFlag</code> can be calculated by:</p> <pre><code>diagDominantFlag = all(diag(A) &gt;= (sum(A, 2) - diag(A))); </code></pre> <p>Thus replacing your double <code>for</code> loop with a one-liner.</p>