# flipdim

flip x block components along a given dimension

## Calling Sequence

    y = flipdim(x, dim [,sb])

## Arguments

x, y

  scalars, vectors, matrices, or hypermatrices of any type, of same sizes

dim

  a positive integer, the dimension number along which the flipping should occur

sb

  a positive integer, the size of the blocks to permute

## Description

Given `x`, a scalar/vector/matrix/hypermatrix of any type and two positive integers `dim` and `sb`, this function flips the x components by blocks of size `sb` along the dimension number `dim` of `x` (`x` and `y` have the same size).

The optional parameter `sb` (for Size Block) allows flipping `x` by blocks of size `sb*size(x,2)` (`dim=1`) or `size(x,1)*sb` (`dim=2`).

## Examples

    // Example 1: flip x components along the first dimension
    x = [1 2 3 4; 5 6 7 8]
    dim = 1
    y = flipdim(x, dim)

    // Example 2: flip x components along the second dimension
    dim = 2
    y = flipdim(x, dim)

    // Example 3: flip x components along the third dimension
    x = matrix(1:24, [3 2 4])
    dim = 3
    y = flipdim(x, dim)

    // Example 4: the first example with complex
    x = [1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i]
    dim = 1
    y = flipdim(x, dim)

    // Integer-encoded numbers:
    x = int16(grand(4, 3, 2, "uin", -9, 9))
    y = flipdim(x, 1)

    // Booleans:
    x = (grand(3, 4, "uin", -9, 9) > 0)
    y = flipdim(x, 2)

    // Texts:
    x = matrix(strsplit("a":"x", 1:23), 4, 6);
    x = x+x
    flipdim(x, 2)

    // Polynomials:
    x = inv_coeff(grand(3, 9, "uin", 0, 3), 2)
    flipdim(x, 1)

    // Rationals:
    n = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
    d = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
    r = n./d
    flipdim(r, 2)

Examples using `sb`:

    X = [0 1 2 3 4 5 6 7 8 9 10 11];
    flipdim(X, 2, 2) // => [10 11   8 9   6 7   4 5   2 3   0 1] // Block size = 2.
    flipdim(X, 2, 3) // => [9 10 11   6 7 8   3 4 5   0 1 2]
    flipdim(X, 2, 4) // => [8 9 10 11   4 5 6 7   0 1 2 3]
    flipdim(X, 2, 6) // => [6 7 8 9 10 11   0 1 2 3 4 5]

    // Error if sb does not divide the targeted dimension of x.
    y = flipdim(x, 2, 5); // size(X) = [1 12] and sb=5 does not divide 12.

## History

5.5.0
Extension from decimals to any type: booleans, integers, strings, polynomials and rationals. New input argument `sb` to flip `x` blockwise.