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

10 Solutions

8 Solvers

Last Solution submitted on Jul 15, 2026

Last 200 Solutions

Solution Comments

Show comments
Loading...

Problem Recent Solvers8

Suggested Problems

More from this Author12

Problem Tags

Community Treasure Hunt

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

Start Hunting!