Cody

# Problem 859. Get the elements of diagonal and antidiagonal for any m-by-n matrix

Solution 1674860

Submitted on 15 Nov 2018 by Sharon Spelt
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 = [10 20 30; 40 50 60; 70 80 90]; diag_correct = [10 50 90]; antidiag_correct = [ 70 50 30]; [A,B]= your_fcn_name(x); assert(isequal(A,diag_correct)) assert(isequal(B,antidiag_correct))

rows = 3 cols = 3 j = 0 n = 4 maxA = 3 antidg_elements = [] dg_elements = [] k = 70 l = 10 antidg_elements = 70 dg_elements = 10 n = 3 j = 1 k = 50 l = 50 antidg_elements = 70 50 dg_elements = 10 50 n = 2 j = 2 k = 30 l = 90 antidg_elements = 70 50 30 dg_elements = 10 50 90 n = 1 j = 3

2   Pass
x = [10 20 30; 40 50 60 ; 70 80 90; 100 74 15]; diag_corrct78 = [10 50 90]; antidiag_corrct78 = [ 100 80 60]; [A3,B3]= your_fcn_name(x); assert(isequal(A3,diag_corrct78)) assert(isequal(B3,antidiag_corrct78))

rows = 4 cols = 3 j = 0 n = 5 maxA = 3 antidg_elements = [] dg_elements = [] k = 100 l = 10 antidg_elements = 100 dg_elements = 10 n = 4 j = 1 k = 80 l = 50 antidg_elements = 100 80 dg_elements = 10 50 n = 3 j = 2 k = 60 l = 90 antidg_elements = 100 80 60 dg_elements = 10 50 90 n = 2 j = 3

3   Pass
x = [10 20 30 58; 40 50 60 68 ; 70 80 90 98]; diag_correct7 = [10 50 90]; antidiag_correct7 = [ 70 50 30]; [A3,B3]= your_fcn_name(x); assert(isequal(A3,diag_correct7)) assert(isequal(B3,antidiag_correct7))

rows = 3 cols = 4 j = 0 n = 4 maxA = 3 antidg_elements = [] dg_elements = [] k = 70 l = 10 antidg_elements = 70 dg_elements = 10 n = 3 j = 1 k = 50 l = 50 antidg_elements = 70 50 dg_elements = 10 50 n = 2 j = 2 k = 30 l = 90 antidg_elements = 70 50 30 dg_elements = 10 50 90 n = 1 j = 3

4   Pass
t = [0 0 0; 1 0 0 ; 0 2 0; 0 0 3]; diag8 = [0 0 0]; antid7 = [ 0 2 0]; [A3,B3]= your_fcn_name(t); assert(isequal(A3,diag8)) assert(isequal(B3,antid7)) % m-by-n matrix where m <= n (5) t = [0 1 0 0; 0 0 2 0 ; 0 0 0 3]; diag8 = [0 0 0]; antid7 = [ 0 0 0]; [A3,B3]= your_fcn_name(t); assert(isequal(A3,diag8)) assert(isequal(B3,antid7))

rows = 4 cols = 3 j = 0 n = 5 maxA = 3 antidg_elements = [] dg_elements = [] k = 0 l = 0 antidg_elements = 0 dg_elements = 0 n = 4 j = 1 k = 2 l = 0 antidg_elements = 0 2 dg_elements = 0 0 n = 3 j = 2 k = 0 l = 0 antidg_elements = 0 2 0 dg_elements = 0 0 0 n = 2 j = 3 rows = 3 cols = 4 j = 0 n = 4 maxA = 3 antidg_elements = [] dg_elements = [] k = 0 l = 0 antidg_elements = 0 dg_elements = 0 n = 3 j = 1 k = 0 l = 0 antidg_elements = 0 0 dg_elements = 0 0 n = 2 j = 2 k = 0 l = 0 antidg_elements = 0 0 0 dg_elements = 0 0 0 n = 1 j = 3