Sum of cross diagonals of a non symmetric matrix

Hi I need to calculate the sum of cross diagonals of a non symmetric matrix. if A=[ 1 2 3 4;5 6 7 8; 9 8 7 3]
I want to calculate the sum of all the diagonals from left to right and store it in an array such as:
B=[1 7 18 19 15 3] Can someone help me to find the logic for this calculation?

댓글 수: 1

Note that the sums you've written are the sums of the antidiagonals, not the diagonals.

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2015년 6월 4일
편집: Guillaume 2015년 6월 4일

0 개 추천

To calculate the sums of the diagonals:
A=[ 1 2 3 4;5 6 7 8; 9 8 7 3]
s = arrayfun(@(d) sum(diag(A, d)), 1-size(A, 1):size(A, 2)-1)
If you really want the antidiagonal sums, then you'll have to flip A.

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

질문:

2015년 6월 4일

답변:

2015년 6월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by