FOLD

Syntax: matrix = FOLD( vector, scalar )

The FOLD function has two arguments. The first must be a vector, and the second a scalar. The result is a matrix formed by folding the data in the vector into the columns of a matrix.

Suppose that vector x has m elements. Then

FOLD(x,n)[i,j] = x[i+(j-1)*n]

for i = 1,2,...,n and j = 1,2,...,m/n.

Note that m must be divisible by n.

Examples

functionresult
FOLD([1:12],3)
| 1 4 7 10 |
| 2 5 8 11 |
| 3 6 9 12 |
FOLD([1:12],4)
| 1 5  9 |
| 2 6 10 |
| 3 7 11 |
| 4 8 12 |

Note: if M is a matrix with R rows, then
FOLD(UNFOLD(M),R) is equal to M
if X is a vector and N is a scalar such than LEN(X) is divisible by N, then
UNFOLD(FOLD(X,N)) is equal to X

  WRAP
  UNFOLD