Cody

# Problem 42635. Maximum of each diagonal

Solution 2049978

Submitted on 7 Dec 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   Fail
assert(isempty(maxdiag([])))

a = 0 b = 0

Output argument "y" (and maybe others) not assigned during call to "maxdiag". Error in Test1 (line 1) assert(isempty(maxdiag([])))

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

a = 1 b = 1

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

a = 100 b = 1

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in maxdiag (line 5) y(k)=max(diag(x,i)); Error in Test3 (line 2) assert(isequal(maxdiag(x),x(end:-1:1)'))

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

a = 1 b = 100

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in maxdiag (line 5) y(k)=max(diag(x,i)); Error in Test4 (line 2) assert(isequal(maxdiag(x),x))

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

a = 2 b = 2

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

a = 3 b = 3

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

a = 1000 b = 1000

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

a = 1000 b = 1000

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

a = 32 b = 32

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]))

a = 10 b = 3

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]))

a = 5 b = 9