Sum of diagonals elements of a matrix - MATLAB Cody - MATLAB Central

Problem 2094. Sum of diagonals elements of a matrix

Difficulty:Rate

Given a matrix, return the sum of all the elements across the diagonals.

E.g. A = [1 2 3; 4 5 6; 7 8 9;]

then, sum = 25 as sum of (1, 3, 7, 9,5)

Solution Stats

40.3% Correct | 59.7% Incorrect
Last Solution submitted on May 08, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers224

Suggested Problems

More from this Author25

Problem Tags

Community Treasure Hunt

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

Start Hunting!