MAT Statement

Assigns values to each element in a dimensioned array.

Syntax

MAT array-name = expression

MAT array-name1 = MAT array-name2

Syntax Elements

array-name, array-name1, array-name2
The names of dimensioned arrays.

expression Any valid DataBasic expression or string the value to which all elements of the array are to be set. This may be expressed as a variable or symbol name, or a numeric or string literal.

Options

The first syntax of the MAT statement shown above is the MAT assignment statement. The second syntax is the MAT copy statement.

Comments

The MAT assignment statement assigns a single value (the result of expression) to all elements in an array. The specified array must have been previously dimensioned by a DIMENSION or COMMON statement.

The MAT copy statement copies array-name2 to array-name1.  The first element of array-name2 becomes the first element of array-name1, and so on.  Each variable must have been dimensioned, and the number of elements in the two arrays must match; if not, an error message is displayed and the program transfers to the debugger.

Arrays are copied in row major order.  For example:

Program Code

Resulting Array Values

DIM X(5,2), Y(10)
FOR I=1 TO 10
    Y(I)=I
NEXT I
.
.
MAT X = MAT Y
X(1,1) = Y(1) = 1
X(1,2) = Y(2) = 2
X(2,1) = Y(3) = 3
.
.
.
X(5,2) = Y(10) = 10

This example dimensions two arrays, both having 10 elements, initializes array Y to the numbers 1 through 10, then copies array Y to array X.

Examples

MAT TABLE=1

Assigns a value of 1 to each element of array TABLE.

MAT XYZ=A+B/C

Assigns the value of expression A+B/C to each element of array XYZ.

DIM A(20), B(20)
.
.
MAT A = MAT B

Dimensions two vectors of equal length and assigns the values of the elements in array B to the corresponding elements in array A.

DIM TAB1(10,10), TAB2(50,2)
.
.
MAT TAB1 = MAT TAB2

Dimensions two arrays to the same number of elements and copies TAB2 values to TAB1 in row major order.