Returns a new matrix with the same shape and items, independent of the original.
Changing the copy leaves the source matrix unchanged. The copy is shallow for object items, which both matrices keep pointing at.
Without a copy, assigning one matrix variable to another only gives the same grid a second name.
Syntax
matrix.copy(id: any matrix type) -> matrix<>
matrix.copy() -> matrix<>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix to duplicate. The copy is independent of the original. |
Returns
matrix<>: A new matrix with the same dimensions and items.
Example
//@version=6
indicator("matrix.copy: independent", overlay = false)
matrix<float> a = matrix.new<float>(2, 2, 1.0)
b = matrix.copy(a)
matrix.set(b, 0, 0, 9.0)
plot(matrix.get(a, 0, 0), "Original stays 1")See also
Runs on Sidechair