Given a square matrix M
, how can you find the sum of the elements on the diagonal? There must be an easier method than this:
sum(sum(diag(diag(M), 0)))
Given a square matrix M
, how can you find the sum of the elements on the diagonal? There must be an easier method than this:
sum(sum(diag(diag(M), 0)))