Sum the numbers on the main diagonal of an n-by-n matrix. For input:

      A = [1 2 4
           3 6 2
           2 4 7]

The output value should equal 14.

Solution Stats

830 Solutions

611 Solvers

Last Solution submitted on Feb 03, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers611

Suggested Problems

Community Treasure Hunt

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

Start Hunting!