Cody

Problem 1167. matrix zigzag

Solution 3794888

Submitted on 23 Nov 2020
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
x = [1 2; 3 4]; y_correct = [1 2 3 4]; assert(isequal(zigzag(x),y_correct))

Index in position 1 exceeds array bounds (must not exceed 2). Error in zigzag (line 2) y = [x(1,1:2) x(2,1) x(3,1) x(2,2) x(1,3) x(2,3) x(3,2:3)] Error in Test1 (line 3) assert(isequal(zigzag(x),y_correct))

2   Pass
x = [ 1 2 3; 4 5 6; 7 8 9]; y_correct = [ 1 2 4 7 5 3 6 8 9]; assert(isequal(zigzag(x),y_correct))

y = 1 2 4 7 5 3 6 8 9

3   Fail
x = magic(4); y_correct = [16 2 5 9 11 3 13 10 7 4 14 6 8 12 15 1]; assert(isequal(zigzag(x),y_correct))

y = 16 2 5 9 11 3 10 7 6

Assertion failed.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!