Collections
A collection is an ordered grouping of elements (which may be literals or other collections).
The [ and ] characters are used to specify the beginning and end of a collection. The main type of collection is a two-dimensional matrix, which is composed of rows and columns. An individual element in a matrix is uniquely identified by its row and column. The , character is used to separate elements within a row. Spaces are also a valid delimiter between elements within a row, but commas are preferred for clarity (see below). The ; character is used to separate rows.
[1,2,3;4,5,6]
is a matrix having 2 rows and 3 columns. The
first element (1) is located in the first row and first column, or the 1,1 position.[[1,2,3];[4,5,6]]
is equivalent to the above example.[[1,2; 3,4]; [5,6]]
is a valid collection because all rows have the
same number of columns.[[1,2; 3,4];5]
is not a valid collection
because the dimensions do not agree.['hello’;’world']
However, since strings are collections of characters, each row must have the same number of characters in order to form a valid matrix.
['hi';'hello']
is not valid.['hi';'he']
or ['hi','hello']
are
valid. The first one creates a matrix (2x2), the second one creates a 1x7 matrix
(concatenated the 2 strings).A single numeric value (a scalar) can always be treated as a collection of 1 row and 1 column.A matrix may be empty as well. To create an empty matrix, use the [] characters with nothing between them. Empty matrices are valid entities in most circumstances, depending on context.
size([1,2,3;4,5,6]) => [2,3]
[,1,2;3,4;,] => [1,2;3,4]
size(3) => [ 1 1]
If spaces are used to separate elements within a row, there are special rules that apply to the + and – characters.
In addition to the collections described above, OML language supports Multidimensional Matrices.