I have to write a function in Octave that creates a zigzag matrix of order n
, where n
is given as an input parameter of the function. The function will have the following header:
function R = zig-zag(n)
For example: zig-zag(5)
should generate a matrix like this:
0 1 5 6 14
2 4 7 13 15
3 8 12 16 21
9 11 17 20 22
10 18 19 23 24
How can I write this as easy as possible in Octave?