Cody

# Problem 42635. Maximum of each diagonal

Solution 1995321

Submitted on 29 Oct 2019
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
assert(isempty(maxdiag([])))

2   Pass
x = randi(100); assert(isequal(maxdiag(x),x))

y = 39

3   Fail
x = randi(100,100,1); assert(isequal(maxdiag(x),x(end:-1:1)'))

y = Columns 1 through 29 61 79 17 93 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 Columns 30 through 58 42 57 44 40 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 Columns 59 through 87 83 55 99 76 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 Columns 88 through 116 31 27 10 72 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 199 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 61 79 17 93 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 Columns 30 through 58 42 57 44 40 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 Columns 59 through 87 83 55 99 76 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 Columns 88 through 116 31 27 10 72 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 79 17 93 Columns 204 through 232 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 42 57 44 40 Columns 233 through 261 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 83 55 99 76 Columns 262 through 290 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 31 27 10 72 Columns 291 through 319 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 320 through 348 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 349 through 377 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 378 through 397 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 61 79 17 93 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 Columns 30 through 58 42 57 44 40 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 Columns 59 through 87 83 55 99 76 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 Columns 88 through 116 31 27 10 72 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 79 17 93 Columns 204 through 232 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 42 57 44 40 Columns 233 through 261 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 83 55 99 76 Columns 262 through 290 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 31 27 10 72 Columns 291 through 319 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 320 through 348 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 349 through 377 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 378 through 406 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 79 17 93 34 21 21 49 94 Columns 407 through 435 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 42 57 44 40 79 11 93 36 78 Columns 436 through 464 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 83 55 99 76 71 11 38 35 29 Columns 465 through 493 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 31 27 10 72 38 90 15 66 64 Columns 494 through 522 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 523 through 551 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 552 through 580 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 581 through 594 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 61 79 17 93 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 Columns 30 through 58 42 57 44 40 79 11 93 36 78 90 24 21 49 34 47 87 99 45 60 15 23 36 81 4 18 94 26 12 8 Columns 59 through 87 83 55 99 76 71 11 38 35 29 60 91 36 51 8 93 24 73 57 33 1 73 44 11 64 11 11 23 34 10 Columns 88 through 116 31 27 10 72 38 90 15 66 64 87 86 64 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 79 17 93 Columns 204 through 232 34 21 21 49 94 22 26 65 15 74 82 63 97 96 50 82 55 58 78 64 65 51 97 66 15 42 57 44 40 Columns 233 through 261 ...

Assertion failed.

4   Fail
x = randi(100,1,100); assert(isequal(maxdiag(x),x))

y = Columns 1 through 29 53 52 65 32 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 Columns 30 through 58 28 26 22 54 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 Columns 59 through 87 86 42 72 23 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 Columns 88 through 116 6 69 61 97 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 199 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 53 52 65 32 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 Columns 30 through 58 28 26 22 54 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 Columns 59 through 87 86 42 72 23 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 Columns 88 through 116 6 69 61 97 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 53 52 65 32 Columns 204 through 232 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 28 26 22 54 Columns 233 through 261 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 86 42 72 23 Columns 262 through 290 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 6 69 61 97 Columns 291 through 319 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 320 through 348 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 349 through 377 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 378 through 397 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 53 52 65 32 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 Columns 30 through 58 28 26 22 54 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 Columns 59 through 87 86 42 72 23 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 Columns 88 through 116 6 69 61 97 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 53 52 65 32 Columns 204 through 232 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 28 26 22 54 Columns 233 through 261 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 86 42 72 23 Columns 262 through 290 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 6 69 61 97 Columns 291 through 319 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 320 through 348 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 349 through 377 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 378 through 406 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 53 52 65 32 10 79 94 100 24 Columns 407 through 435 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 28 26 22 54 71 61 20 18 13 Columns 436 through 464 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 86 42 72 23 33 43 5 22 5 Columns 465 through 493 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 6 69 61 97 61 52 27 52 2 Columns 494 through 522 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 523 through 551 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 552 through 580 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 581 through 594 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = Columns 1 through 29 53 52 65 32 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 Columns 30 through 58 28 26 22 54 71 61 20 18 13 77 49 74 81 40 34 23 66 71 69 44 36 100 82 58 64 9 35 17 90 Columns 59 through 87 86 42 72 23 33 43 5 22 5 13 87 48 79 82 37 81 25 29 13 46 90 93 78 98 78 46 70 51 87 Columns 88 through 116 6 69 61 97 61 52 27 52 2 8 91 89 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 117 through 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 146 through 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 175 through 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 53 52 65 32 Columns 204 through 232 10 79 94 100 24 44 79 40 21 44 94 60 22 15 34 47 80 91 54 12 69 16 68 50 87 28 26 22 54 Columns 233 through 261 ...

Assertion failed.

5   Pass
x = eye(2); assert(isequal(maxdiag(x),[0 1 0]))

y = 0 y = 0 1 y = 0 1 0

6   Pass
x = magic(3); assert(isequal(maxdiag(x),[4 9 8 7 6]))

y = 4 y = 4 9 y = 4 9 8 y = 4 9 8 7 y = 4 9 8 7 6

7   Pass
x = flipud(hankel(1:1000)); assert(isequal(maxdiag(x),[1:1000,zeros(1,1000-1)]))

y = 1 y = 1 2 y = 1 2 3 y = 1 2 3 4 y = 1 2 3 4 5 y = 1 2 3 4 5 6 y = 1 2 3 4 5 6 7 y = 1 2 3 4 5 6 7 8 y = 1 2 3 4 5 6 7 8 9 y = 1 2 3 4 5 6 7 8 9 10 y = 1 2 3 4 5 6 7 8 9 10 11 y = 1 2 3 4 5 6 7 8 9 10 11 12 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 y = 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 = 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 26 y = 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 26 27 y = 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 26 27 28 y = 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 26 27 28 29 y = Columns 1 through 29 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 26 27 28 29 Column 30 30 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 31 30 31 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 32 30 31 32 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 33 30 31 32 33 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 34 30 31 32 33 34 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 35 30 31 32 33 34 35 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 36 30 31 32 33 34 35 36 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 37 30 31 32 33 34 35 36 37 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 38 30 31 32 33 34 35 36 37 38 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 39 30 31 32 33 34 35 36 37 38 39 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 40 30 31 32 33 34 35 36 37 38 39 40 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 41 30 31 32 33 34 35 36 37 38 39 40 41 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 42 30 31 32 33 34 35 36 37 38 39 40 41 42 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 43 30 31 32 33 34 35 36 37 38 39 40 41 42 43 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 44 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 45 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 46 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 47 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 48 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 49 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 50 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 51 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 52 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 y = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21...

8   Pass
x = toeplitz(1:1000); assert(isequal(maxdiag(x),[1000:-1:1,2:1000]))

y = 1000 y = 1000 999 y = 1000 999 998 y = 1000 999 998 997 y = 1000 999 998 997 996 y = 1000 999 998 997 996 995 y = 1000 999 998 997 996 995 994 y = 1000 999 998 997 996 995 994 993 y = 1000 999 998 997 996 995 994 993 992 y = 1000 999 998 997 996 995 994 993 992 991 y = 1000 999 998 997 996 995 994 993 992 991 990 y = 1000 999 998 997 996 995 994 993 992 991 990 989 y = 1000 999 998 997 996 995 994 993 992 991 990 989 988 y = 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Column 15 986 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 16 986 985 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 17 986 985 984 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 18 986 985 984 983 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 19 986 985 984 983 982 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 20 986 985 984 983 982 981 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 21 986 985 984 983 982 981 980 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 22 986 985 984 983 982 981 980 979 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 23 986 985 984 983 982 981 980 979 978 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 24 986 985 984 983 982 981 980 979 978 977 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 25 986 985 984 983 982 981 980 979 978 977 976 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 26 986 985 984 983 982 981 980 979 978 977 976 975 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 27 986 985 984 983 982 981 980 979 978 977 976 975 974 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Column 29 972 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 30 972 971 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 31 972 971 970 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 32 972 971 970 969 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 33 972 971 970 969 968 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 34 972 971 970 969 968 967 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 35 972 971 970 969 968 967 966 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 36 972 971 970 969 968 967 966 965 y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29...

9   Pass
N = randi(1000); x = fliplr(toeplitz(1:N)); assert(isequal(maxdiag(x),[1:N,N-1:-1:1]))

y = 1 y = 1 2 y = 1 2 3 y = 1 2 3 4 y = 1 2 3 4 5 y = 1 2 3 4 5 6 y = 1 2 3 4 5 6 7 y = 1 2 3 4 5 6 7 8 y = 1 2 3 4 5 6 7 8 9 y = 1 2 3 4 5 6 7 8 9 10 y = 1 2 3 4 5 6 7 8 9 10 11 y = 1 2 3 4 5 6 7 8 9 10 11 12 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 y = 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 = 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 26 y = 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 26 27 y = 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 26 27 28 y = 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 26 27 28 29 y = Columns 1 through 29 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 26 27 28 29 Column 30 30 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 31 30 31 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 32 30 31 32 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 33 30 31 32 33 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 34 30 31 32 33 34 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 35 30 31 32 33 34 35 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 36 30 31 32 33 34 35 36 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 37 30 31 32 33 34 35 36 37 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 38 30 31 32 33 34 35 36 37 38 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 39 30 31 32 33 34 35 36 37 38 39 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 40 30 31 32 33 34 35 36 37 38 39 40 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 41 30 31 32 33 34 35 36 37 38 39 40 41 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 42 30 31 32 33 34 35 36 37 38 39 40 41 42 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 43 30 31 32 33 34 35 36 37 38 39 40 41 42 43 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 44 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 45 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 46 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 47 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 48 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 49 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 50 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 51 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 y = Columns 1 through 29 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 26 27 28 29 Columns 30 through 52 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 y = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21...

10   Pass
x = magic(10); x = x(:,1:3); assert(isequal(maxdiag(x),[11 18 100 94 17 86 93 87 98 92 99 1]))

y = 11 y = 11 18 y = 11 18 100 y = 11 18 100 94 y = 11 18 100 94 17 y = 11 18 100 94 17 86 y = 11 18 100 94 17 86 93 y = 11 18 100 94 17 86 93 87 y = 11 18 100 94 17 86 93 87 98 y = 11 18 100 94 17 86 93 87 98 92 y = 11 18 100 94 17 86 93 87 98 92 99 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1 y = 11 18 100 94 17 86 93 87 98 92 99 1

11   Pass
x = hankel(-4:0,0:-2:-16); assert(isequal(maxdiag(x),[0 -1 0 -1 0 -1 0 -1 0 -2 -4 -6 -8]))

y = 0×1 empty double column vector y = 0×2 empty double matrix y = 0×3 empty double matrix y = 0×4 empty double matrix y = 0 y = 0 -1 y = 0 -1 0 y = 0 -1 0 -1 y = 0 -1 0 -1 0 y = 0 -1 0 -1 0 -1 y = 0 -1 0 -1 0 -1 0 y = 0 -1 0 -1 0 -1 0 -1 y = 0 -1 0 -1 0 -1 0 -1 0 y = 0 -1 0 -1 0 -1 0 -1 0 -2 y = 0 -1 0 -1 0 -1 0 -1 0 -2 -4 y = 0 -1 0 -1 0 -1 0 -1 0 -2 -4 -6 y = 0 -1 0 -1 0 -1 0 -1 0 -2 -4 -6 -8