flip horizontally / vertically

Prev Next

Function Names

flip horizontally, flip vertically

Description

This function flips a m x n matrix using a horizontal or vertical axis.

The matrix must be rectangular. Consider filling short rows with blanks or zeros before flipping.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
1
input
matrix input matrix

Matrix to be transposed

Return value

TypeDescription
matrix Flipped matrix

Examples

a[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };

echo matrix( "0", 3, '|', 'a[] = ', a[] );

echo("Flip horizontally:");
h[] = flip horizontally( a[] );
echo matrix( "0", 3, '|', 'h[] = ', h[] );

echo("Flip vertically:");
v[] = flip vertically( a[] );
echo matrix( "0", 3, '|', 'v[] = ', v[] );

Output

      |  1    2    3|
      |  4    5    6|
a[] = |  7    8    9|
      | 10   11   12|

Flip horizontally:
      |  3    2    1|
      |  6    5    4|
h[] = |  9    8    7|
      | 12   11   10|

Flip vertically:
      | 10   11   12|
      |  7    8    9|
v[] = |  4    5    6|
      |  1    2    3|

Try it yourself: Open LIB_Function_flip_horizontally.b4p in B4P_Examples.zip. Decompress before use.

See also

table flip columns
table flip rows