...
Vectors are created using the vector() function and matrices with the matrix() function. Their elements are read or set using the [] operator :
...
#
...
Allocate
...
a
...
vector
...
of
...
5
...
elements
...
...
v
...
=
...
vector(5)
...
...
#
...
Initialise
...
their
...
value
...
...
for
...
i
...
=
...
1
...
to
...
5
...
do
...
...
v[i]
...
=
...
i
...
...
end
...
for
...
Vector literals can be written using the | character :
...
v
...
=
...
|3,6,7,9,10|
How operators and functions work on vectors
...
X[i] = ith value of vector X:
...
#
...
copies
...
element
...
2
...
of
...
vector
...
X
...
into
...
Y
...
...
Y
...
=
...
X[2]
...
More sophisticated usage of [] allows you to extract or refer to a range of values.
x[i,j] = all values of vector X from the ith to the jth :
...
#
...
copies
...
values
...
3,
...
4,
...
5,
...
6,
...
7
...
and
...
8
...
of
...
X
...
into
...
Y
...
...
Y
...
=
...
X[3,8]
...
X[i,j,k] = every kth value of vector X, from the ith to the jth :
...
#
...
copies
...
values
...
1,
...
5,
...
9,
...
13,
...
17
...
of
...
X
...
into
...
Y
...
...
Y
...
=
...
X[1,20,4]
...
An additional fourth parameter specifies how many elements to extract from the current step :
...
#
...
copies
...
values
...
1,2,
...
5,6,
...
9,10,
...
13,14,
...
17,18
...
of
...
X
...
into
...
Y
...
Y
...
=
...
X[1,20,4,2]
If a vector is holding data representing a rectangular structure, this form could be used to extract a 'sub-area'.
...
Vectors can contain missing values. These can be assigned or tested for using the global variable vector_missing_value
. Operations between vectors will bypass missing values. For example, if we represent a missing value with an 'x', then the result of
|1,2,3,x,5|
...
+
...
|2,2,2,2,x|
will be
|3,4,5,x,x|
See the descriptions for particular functions and operators for specific details. The bitmap()
function can be used to translate between missing values and 'real' values. When a vector is printed with the print()
function, missing values are represented by an 'x
'.
When a vector is generated from a fieldset, e.g.
a
...
=
...
values(fieldset)
missing values from the field are automatically translated into missing values in the vector. The same is true when obtaining a vector of values from a geopoints variable. Missing values in vectors are also translated correctly when inserted into fieldsets and geopoints.