MATLAB: How to sum only few values in a diagonal matrix

diagonal

if I have a diagonal matrix, and I use sum(diag(A)) , it gives me the sum of entire diagonal, but I only want the sum of lets say 1st three values in the diagonal? How can I add them?
Thank you!!

Best Answer

Rida, use
sum(diag(A(1:3,1:3)))
Related Question