transpose

Prev Next

Function Names

transpose

Description

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

The matrix must not necessarily be recctangular. All matrices can be transposed if the number of elements in the rows below contain the same number of elements or fewer elements than the previous row. Otherwise, the matrix cannot be transposed due missing values to include.

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

      echo( transpose( { {1,2,3,4}, {a,b,c,d}, {5,6,7,8} } ) ); // Rectangular matrix
      echo( transpose( { {1,2,3,4}, {a,b,c}, {5,6} } ) ); // Bottom rows with fewer elements
      // echo( transpose( { {1,2,3,4}, {a,b,c}, {5,6,7,8} } ) ); // Would cause an exception

Output

{{1,'a',5},{2,'b',6},{3,'c',7},{4,'d',8}}
{{1,'a',5},{2,'b',6},{3,'c'},{4}}
Try it yourself: Open LIB_Function_transpose.b4p in B4P_Examples.zip. Decompress before use.