Dear @bmtran, how can does work? I ask this because you add the vector diag(M) to a matrix. I think you should write
diag(diag(M)) instead of diag(M). Am I wrong?
it should be fairly easy to diagnose what i'm doing if you run each argument of my code separately in MATLAB and look at what it's doing, but I don't wanna give anything away to people who have yet to solve this problem.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
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))
|
2 | Pass |
M=magic(2);
y_correct=[2 3; 4 1];
assert(isequal(flipDiagonal(M),y_correct))
|
3 | Pass |
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))
|
4 | Pass |
M=[1];
y_correct=[1];
assert(isequal(flipDiagonal(M),y_correct))
|
5 | Pass |
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))
|
6 | Pass |
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))
|
Basics: 'Find the eigenvalues of given matrix
257 Solvers
202 Solvers
261 Solvers
198 Solvers
Sum the 'edge' values of a matrix
154 Solvers