Cody

# Problem 545. Flip the main diagonal of a matrix

Solution 1939469

Submitted on 17 Sep 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
M=magic(5); y_correct = [9, 24,1,8 ,15; 23 ,21,7,14,16; ... 4,6,13,20,22; 10,12,19,5,3; 11,18,25,2,17]; assert(isequal(flipDiagonal(M),y_correct))

b = 5 5

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test1 (line 4) assert(isequal(flipDiagonal(M),y_correct))

2   Fail
M=magic(2); y_correct=[2 3; 4 1]; assert(isequal(flipDiagonal(M),y_correct))

b = 2 2

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test2 (line 3) assert(isequal(flipDiagonal(M),y_correct))

3   Fail
M=ones(4); M(2,2)=4; M(3,3)=9; M(4,4)=16; y_correct=ones(4); y_correct(1,1)=16; y_correct(2,2)=9; y_correct(3,3)=4; assert(isequal(flipDiagonal(M),y_correct))

b = 4 4

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test3 (line 5) assert(isequal(flipDiagonal(M),y_correct))

4   Fail
M=[1]; y_correct=[1]; assert(isequal(flipDiagonal(M),y_correct))

b = 1 1

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test4 (line 3) assert(isequal(flipDiagonal(M),y_correct))

5   Fail
M=reshape(1:25,[5,5]); y_correct=[25 2 3 4 5; 6 19 8 9 10; ... 11 12 13 14 15; 16 17 18 7 20; 21 22 23 24 1]'; assert(isequal(flipDiagonal(M),y_correct))

b = 5 5

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test5 (line 4) assert(isequal(flipDiagonal(M),y_correct))

6   Fail
M=[1,1,1,1;2,2,2,2;3,3,3,3;4,4,4,4]; y_correct=[4,1,1,1;2,3,2,2;3,3,2,3;4,4,4,1]; assert(isequal(flipDiagonal(M),y_correct))

b = 4 4

Unable to perform assignment because the left and right sides have a different number of elements. Error in flipDiagonal (line 3) x(1:length(x)+1:b(1)*b(2))=x(b(1)*b(2):-length(x)+1:1) Error in Test6 (line 3) assert(isequal(flipDiagonal(M),y_correct))