Cody

# Problem 459. Sum of diagonal of a square matrix

Solution 1986106

Submitted on 22 Oct 2019 by Ngo Minh Ngoc
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = magic(4); y_correct = sum(diag(x)); assert(isequal(your_fcn_name(x),y_correct))

a = 4 m = 136 x = 0 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 x = 0 2 3 13 5 0 10 8 9 7 6 12 4 14 15 1 x = 0 2 3 13 5 0 10 8 9 7 0 12 4 14 15 1 x = 0 2 3 13 5 0 10 8 9 7 0 12 4 14 15 0 n = 102 y = 34

2   Pass
x = ones(5); y_correct = sum(diag(x)); assert(isequal(your_fcn_name(x),y_correct))

a = 5 m = 25 x = 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x = 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 x = 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 n = 20 y = 5

### Community Treasure Hunt

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

Start Hunting!