Cody

Problem 45485. Count the non-zero elements along the diagonals that are immediately next to the main diagonal

Solution 2269294

Submitted on 10 May 2020 by Syed Shahed
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
a =magic(4); b_correct = 6; assert(isequal(CountNearestDiagonalNonZeros(a),b_correct))

2   Pass
a =[-1 2 0 -6;0 1 2 -15;14 7 0 i;30 -1 0 -2]; b_correct = 4; assert(isequal(CountNearestDiagonalNonZeros(a),b_correct))

3   Pass
a =zeros(6); b_correct = 0; assert(isequal(CountNearestDiagonalNonZeros(a),b_correct))

4   Pass
a =[-4 -3 2 1;-9 0 0 1;1 5 -5 0;2 2 -1 4]; b_correct =4; assert(isequal(CountNearestDiagonalNonZeros(a),b_correct))