If I have the following matrix
a = [1 2 3; 4 5 6; 7 8 10a = 1 2 3 4 5 6 7 8 10
How do I sum the diagonal of 7,5,3? I know that to sum 1,5,10 I use
sum(diag(a))
But when I try
sum(diag(a,2))
The answer is 3. Is there a built in function that calculates the sum, or do I have to make a while loop?
Best Answer