Arrays

Arrays are implemented as indexed lists of user variables. The elements in an array are not limited to a single type of variable. Arrays must be created explicitly before being referenced. The size of an array cannot be changed after creation. All elements are initially undefined. In most places an array element can be used instead of a named user variable.

The cardinality (number of elements) of array A is given by the expression 3#3A3#3.

Example:

    array A[6]
    A[1] = 1
    A[2] = 2.0
    A[3] = {3.0, 3.0}
    A[4] = "four"
    A[6] = A[2]**3
    array B[6] = [ 1, 2.0, A[3], "four", , B[2]**3 ]

    do for [i=1:6] { print A[i], B[i] }
        1 1
        2.0 2.0
        {3.0, 3.0} {3.0, 3.0}
        four four
        <undefined> <undefined>
        8.0 8.0

Note: Arrays and variables share the same namespace. For example, assignment of a string variable named FOO will destroy any previously created array with name FOO.

The name of an array can be used in a plot, splot, fit, or stats command. This is equivalent to providing a file in which column 1 holds the array index (from 1 to size), column 2 holds the value of real(A[i]) and column 3 holds the value of imag(A[i]).

Example:

    array A[200]
    do for [i=1:200] { A[i] = sin(i * pi/100.) }
    plot A title "sin(x) in centiradians"

When plotting the imaginary component of complex array values, it may be referenced either as imag(A[$1]) or as $3. These two commands are equivalent

    plot A using (real(A[$1])) : (imag(A[$1]))
    plot A using 2:3