Problem 44102. Stop a ZigZag scanning N*N Matrix at any diag you want
Suppose that we have a 2-D matrix and we try to obtain a 1-D array in zig-zag order, but not all values of our 2-D matrix e.g., for matrix
x= [1 2 3; 4 5 6; 7 8 9]
the resulting 1-D array should be
stop_zig(x,3)=[ 1 2 4 7 5 3]
stop_zig(x,1)=1
stop_zig(x,-1)=9
stop_zig(x,-2)=[9 8 6]
Solution Stats
Problem Comments
-
1 Comment
yurenchu
on 25 Apr 2017
I'd suggest adding test cases in which n (or abs(n)) is larger than the dimension of x; for example, x is a 4-by-4 matrix and n = 6.
Solution Comments
Show commentsProblem Recent Solvers15
Suggested Problems
-
Calculate the Levenshtein distance between two strings
1495 Solvers
-
The Hitchhiker's Guide to MATLAB
3373 Solvers
-
584 Solvers
-
Arrange Vector in descending order
12837 Solvers
-
Golomb's self-describing sequence (based on Euler 341)
175 Solvers
More from this Author14
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!