Compute the sum of the diagonal elements of an array (vector or matrix).
If array is not square return the char array: 'no-square'
If the input is empty, return [].
If the input is a scalar return the scalar number.
If any diagonal element is NaN, return NaN.
If any diagonal element is Inf, return Inf.
If both NaN and Inf appear among the diagonal, return -1.
Some built-in functions are forbidden.

Solution Stats

8 Solutions

7 Solvers

Last Solution submitted on Jun 06, 2026

Last 200 Solutions

Solution Comments

Show comments
Loading...

Problem Recent Solvers7

Suggested Problems

More from this Author10

Problem Tags

Community Treasure Hunt

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

Start Hunting!