transpose

Prev Next

Function Names

transpose

Description

This function transposes a m x n matrix to a n x m matrix.

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

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 Transposed matrix

Examples

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

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

echo("Transpose matrix:");
t[] = transpose( a[] );
echo matrix( "0", 3, '|', 't[] = ', t[] );

Output

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

Transpose matrix:
      |  1    4    7   10|
t[] = |  2    5    8   11|
      |  3    6    9   12|

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

See also

table transpose