# 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.

Example:

[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.

A row vector is a matrix that has only one row. A column vector is a matrix that has only one column. Collections can be composed of other collections. For example:

[[1,2,3];[4,5,6]]

is equivalent to the above example.

When creating collections of collections, the dimensions of all entities must agree. In the previous example, both collections were 1x3 vectors, so it is valid.
[[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.

Collections may contain strings as well:
['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.

Invalid Example:
['hi';'hello']

is not valid.

But
['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.

The size function can be used to determine the number of rows and columns in a collection. It returns a vector containing the number of rows and columns of the element passed to it.
size([1,2,3;4,5,6]) => [2,3]
Any leading or trailing ,’s or ;’s used in the creation of a collection are ignored, but it is not considered good programming practice to have this.
[,1,2;3,4;,] => [1,2;3,4]
Note that a single element, or scalar, behaves like a collection of size 1x1.
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.