I have a matrix like A and I want to calculate the sum of each diagonal of this matrix and show it in a vector like Y.
A=[1 2 3; 4 5 6; 7 8 9]
Y=[3 8 15 12 7]
I know the code
[sum(diag(y,2)),sum(diag(y,1)),sum(diag(y,0)),sum(diag (y,-1)),sum(diag (y,-2))]
but i want to write it as a function.