Cody

# Problem 2094. Sum of diagonals elements of a matrix

Solution 382567

Submitted on 9 Jan 2014 by Rahul Shinde
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 = [1 2 3;4 5 6; 7 8 9;]; y_correct = 25; assert(isequal(DiagSum(x),y_correct));

B = 3 2 1 6 5 4 9 8 7 m = 1 5 9 c = 5 z = 25

2   Pass
%% x = [1 2 3 4 5;6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20; 21 22 23 24 25;]; y_correct = 117; assert(isequal(DiagSum(x),y_correct));

B = 5 4 3 2 1 10 9 8 7 6 15 14 13 12 11 20 19 18 17 16 25 24 23 22 21 m = 1 7 13 19 25 c = 13 z = 117

3   Pass
%% x = ones(7); y_correct = 13; assert(isequal(DiagSum(x),y_correct));

B = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 m = 1 1 1 1 1 1 1 c = 1 z = 13

4   Pass
%% x = magic(9); y_correct = 697; assert(isequal(DiagSum(x),y_correct));

B = 45 34 23 12 1 80 69 58 47 46 44 33 22 11 9 79 68 57 56 54 43 32 21 10 8 78 67 66 55 53 42 31 20 18 7 77 76 65 63 52 41 30 19 17 6 5 75 64 62 51 40 29 27 16 15 4 74 72 61 50 39 28 26 25 14 3 73 71 60 49 38 36 35 24 13 2 81 70 59 48 37 m = 47 68 8 20 41 62 74 14 35 c = 41 z = 697

### Community Treasure Hunt

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

Start Hunting!