Mat Cpy Command

Purpose

copies a number of rows with a number of elements, from row/column offset in the source matrix to row/column offset in the target matrix.

Syntax

Mat Cpy a([i, j])=b([k, l])[,h, w]

i, j, k, l, w, h:integer expression

a(), b():one or two dimensional floating point arrays

Description

Mat Cpy a([i, j])=b([k, l])[,h, w] copies h rows with w elements in matrix b(), from l and k row/column offset in matrix b() to i and j row/column offset in matrix a(). The maximum number of elements copied is equivalent to the minimum number allowed when dimensioning the matrices, the number of rows (h) and the number of elements per row (w).

If Mat Cpy is used on vectors j and l are ignored. Following a Dim a(n),b(m) the a() and b() are interpreted as row vectors, that is to say as matrices of type (1,n) and (1,m).

To handle a() and b() as column vectors, they must be dimension as matrices of type (n,1) and (m,1), that is to say as Dim a(n,1),b(m,1).

Mat Cpy always handles vectors as column vectors, regardless of their type, so in order to use the correct Mat Cpy syntax with vectors Mat Cpy a(n,1)=b(m,1) must always be used.

If the h and w parameters in Mat Cpy are given explicitly, the following rules apply when copying vectors:

When w => 1 only the h parameter is taken into account. When w=0 no copying takes place.

When h =>1, the w is taken into account only when b() is a row vector and a() is a column vector. Here too, no copying takes place when h=0.

Example

OpenW 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set a() = 1

Mat Set b() = 5

Mat Cpy a(2, 2) = b(3, 4), 3, 3

Mat Print a()

Prints:

1,1,1,1,1
1,5,5,5,1
1,5,5,5,1

Remarks

If some indices are dropped - due to the given width (w) or height (h) - Mat Cpy can result in the following special cases:

Mat Cpy a() = b()

copies into matrix a() all elements of matrix b() for which there are identical indices in matrix a() as in the following example:

OpenW 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set b() = 5

Mat Cpy a() = b()

Mat Print a()

prints

5,5,5,5,5
5,5,5,5,5
5,5,5,5,5


Mat Cpy a(i, j)=b()

copies all elements in matrix b(), from row/column offset defined with Mat BASE, to row/column offset defined with i and j in matrix a(). The maximum number of elements copied is equivalent to the minimum number allowed when dimensioning the matrices, the number of rows (h) and the number of elements per row (w). Example:

OpenW 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set a() = 1

Mat Set b() = 5

Mat Cpy a(2, 2) = b()

Mat Print a()

Prints:

1,1,1,1,1
1,5,5,5,5
1,5,5,5,5


Mat Cpy a() = b(k, l)

copies all elements in matrix b(), from row/column offset defined with k and l, to row/column offset defined with Mat BASE in matrix a(). The maximum number of elements copied is equivalent to the minimum number allowed when dimensioning the matrices, the number of rows (h) and the number of elements per row (w). Example:

OpenW 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set a() = 1

Mat Set b() = 5

Mat Cpy a() = b(4, 4)

Mat Print a()

Prints:

5,5,5,1,1
5,5,5,1,1
5,5,5,1,1


Mat Cpy a(i, j) = b(k, l)

copies all elements in matrix b(), from row/column offset defined with k and l, to row/column offset defined with i and j in matrix a(). The maximum number of elements copied is equivalent to the minimum number allowed when dimensioning the matrices, the number of rows (h) and the number of elements per row (w). Example:

OpenW # 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set a() = 1

Mat Set b() = 5

Mat Cpy a(2, 2) = b(4, 4)

Mat Print a()

Prints:

1,1,1,1,1
1,5,5,5,1
1,5,5,5,1


Mat Cpy a()=b(), h, w

copies h rows and w elements in matrix b(), from row/column offset defined with Mat BASE, to row/column offset matrix a(). The maximum number of elements copied is equivalent to the minimum number allowed when dimensioning the matrices, the number of rows (h) and the number of elements per row (w). Example:

OpenW # 1

Global Double a(1 .. 3, 1 .. 5)

Global Double b(1 .. 6, 1 .. 6)

Mat Set a() = 1

Mat Set b() = 5

Mat Cpy a() = b(), 3, 3

Mat Print a()

Prints:

5,5,5,1,1
5,5,5,1,1
5,5,5,1,1

See Also

MatX Cpy, Mat Trans

{Created by Sjouke Hamstra; Last updated: 14/10/2014 by James Gaite}