This solution is outdated. To rescore this solution, sign in.
Test #5 is incorrect. Transpose on x makes the diagonal [1 5 9], [1 6 11] are not on any diagonal. #5 is the transpose of #4 and taking the transpose does not change the diagonal, unless you have some other definition for diagonal. A good solution is x(find(eye(size(x))))
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
x = [1:10];
y_correct = 1;
assert(isequal(diagonal(x),y_correct))
|
2 | Pass |
%%
x = [1:10]';
y_correct = 1;
assert(isequal(diagonal(x),y_correct))
|
3 | Pass |
%%
x = magic(3);
y_correct = [8 5 2];
assert(isequal(diagonal(x),y_correct))
|
4 | Pass |
%%
x = [1:3;4:6;7:9;10:12];
y_correct = [1 5 9];
assert(isequal(diagonal(x),y_correct))
|
5 | Fail |
%%
x = [1:3;4:6;7:9;10:12]';
y_correct = [1 6 11];
assert(isequal(diagonal(x),y_correct))
Error: Assertion failed.
|
Is my wife right? Now with even more wrong husband
1241 Solvers
Sum all integers from 1 to 2^n
8419 Solvers
329 Solvers
Create a square matrix of multiples
383 Solvers
390 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!