Sum along each diagonal of a matrix - MATLAB Cody - MATLAB Central

Problem 60759. Sum along each diagonal of a matrix

Difficulty:Rate
Write a routine that returns the sums along the diagonals of a given matrix, A, where the first diagonal is the bottom left corner of the matrix and the final diagonal is the top right corner. For example if,
A =
7 9 4 5 7 5 10 10
6 2 10 2 8 6 8 6
3 3 5 3 3 1 5 6
4 2 2 5 2 3 6 3
5 3 10 6 3 9 3 5
3 5 10 3 4 1 5 7
the desired output will be,
y =
3
10
17
18
21
23
38
22
25
21
19
16
10

Solution Stats

42.22% Correct | 57.78% Incorrect
Last Solution submitted on May 04, 2025

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
3

Problem Recent Solvers16

Suggested Problems

More from this Author4

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page