Skip to content

4.2 Matrix based operations

Davide Magni edited this page Oct 24, 2016 · 2 revisions

Koala features a some functions dedicated to matrixes, also known as two-dimensional arrays. These function are dedicated to numeric matrixes: trying to use them on string arrays is not possible and will return compilation errors.

None of the functions listed here below is an inline function, therefore you need to assign their values to a variable before being able to process the output value. See the example below:

value := max_value(array)
index := search(array, value)

copy_matrix

This function allows to copy a two-dimensional array (a.k.a. “matrix”) inside another one. Obviously, you have to make sure that both the source and the target matrix have the same size. In order to prevent errors and script warnings, though, we set up some simple safety checks which avoid wrong copying in case that the two matrixes, for some reason, do have different size: the matrixes will be copied only to the maximum index of the smallest matrix. For instance, if matrix_1 has size 80*4 and matrix_2 has size 155*4, the last index which will be copied is 79*4.

The copy can happen in four different modes according to how you'd like to sort the matrix itself. These modes are explained below.

copy_matrix(<source_mtx>, <target_arr>, <source_cols>, <row_to_copy>, <mode>)

  • source_mtx Name of the matrix to copy from.
  • target_arr Name of the array to copy to.
  • source_cols Amount of columns of the source matrix. Needed to know exactly where to copy from and to.
  • row_to_copy Row of the matrix which will be copied in the target array.
  • mode Copy mode. There are four modes available.
    • NORMAL: each entry has the same position on both the arrays.
    • INVERT: the position of each entry is inverted. The last value found in source_arr is the first value of target_arr.
    • SORT_ASC: after copying, sort target_arr from the smallest to the higehest value.
    • SORT_DESC: after copying, sort target_arr from the highest to the smallest value.
Clone this wiki locally