Find the sum of all diagonal values ​​in a matrix?

2 vues (au cours des 30 derniers jours)
Berkay Eceoglu
Berkay Eceoglu le 6 Juil 2020
Commenté : Rena Berman le 22 Juil 2020
In a 5x5 matrix, I want to find the sum of all short and long diagonals from both the left and right sides. How can I write a for-if loop?
Example: A= 2 4 1 5 6
2 5 3 1 8
3 4 6 7 1
1 2 1 4 3
9 5 2 5 1
Left:
1+5=6
3+2+2=7
2+4+1+5=12
2+5+6+4+1=18
....
  3 commentaires
Stephen23
Stephen23 le 7 Juil 2020
Original question by Berkay Eceoglu recovered from Google Cache:
"Find the sum of all diagonal values ​​in a matrix?"
In a 5x5 matrix, I want to find the sum of all short and long diagonals from both the left and right sides. How can I write a for-if loop?
Example: A= 2 4 1 5 6
2 5 3 1 8
3 4 6 7 1
1 2 1 4 3
9 5 2 5 1
Left:
1+5=6
3+2+2=7
2+4+1+5=12
2+5+6+4+1=18
Rena Berman
Rena Berman le 22 Juil 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

madhan ravi
madhan ravi le 6 Juil 2020
doc diag
doc sum

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by