Exchanges two columns of a matrix in place.
The two columns trade items; all other columns stay put. Use it to reorder variables in a table of observations.
A column swapped with itself is unchanged.
Syntax
matrix.swap_columns(id: any matrix type, column1: series int, column2: series int) -> void
matrix.swap_columns(column1: series int, column2: series int) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix whose two columns trade places in place. |
| column1 | series int | required | Index of the first column. |
| column2 | series int | required | Index of the second column. |
Returns
Nothing.
Example
//@version=6
indicator("matrix.swap_columns: swap", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 0.0)
matrix.set(m, 0, 0, 1.0)
matrix.set(m, 0, 1, 2.0)
matrix.swap_columns(m, 0, 1)
plot(matrix.get(m, 0, 0), "Now 2")See also
Runs on Sidechair