ROLL

Syntax: | `vector = ROLL( vector, scalar ) matrix = ROLL( matrix, scalar )`

The `ROLL` function accepts either a vector or a matrix as its first argument. It shifts the elements of a vector or the rows of a matrix by the specified step size, the scalar second argument.

Suppose the step size is n.

• | If n > 0, the last n elements of the vector or the last n rows of the matrix are rolled around to the beginning.
• | If n = 0, the vector or matrix is returned unchanged.
• | If n < 0, the first n elements of the vector or the first n rows of the matrix are rolled around to the end.

If the step size is not an integer, then linear interpolation is used to generate new values.

Examples

function | result
`ROLL([1:10],2)` | `[9;10;1;2;3;4;5;6;7;8]`
`ROLL([1:10],-2)` | `[3;4;5;6;7;8;9;10;1;2]`
`ROLL([1:10],1.7)` | `[9.3;7.3;1.3;2.3;3.3;4.3;5.3;6.3;7.3;8.3]`

Suppose you have a matrix `M`

                | 1  2  3  4 |
            M = | 5  6  7  8 |
                | 9 10 11 12 |

function | result
`ROLL(M,2)` |
`| 5 6 7 8 |`
`| 9 10 11 12 |`
`| 1 2 3 4 |`
`ROLL(M,-1)` |
`| 5 6 7 8 |`
`| 9 10 11 12 |`
`| 1 2 3 4 |`
`ROLL(M,1.5)` |
`| 7 8 9 10 |`
`| 5 6 7 8 |`
`| 3 4 5 6 |`