Referencing an Item of an Array

If required, you can access a particular item of the array A collection of variables that share common output attributes and can be manipulated in GoldSim elements or input expressions. in an expression. You do this by using brackets [ ].

For example,

Data1[Monday]

references a single (scalar An output consisting of a single value or condition.) value representing the second item of the vector A one-dimensional array. Data1 (defined by the set "Days", which begins with Sunday).

Similarly,

Data2[Monday, Peaches]

references a single (scalar) value representing the item in the second row and third column of the matrix A two-dimensional array. Data2 (with the rows defined by the set "Days", and the columns defined by the set "Fruit", which consists of Apples, Oranges and Peaches).

When referencing array items, you can also use variables as the arguments. For example, if Data1 was a vector of "Days", and X was a scalar value, you could write the following in an expression:

Data1[X]

If X was 3, it would return the 3rd item in the vector (i.e., Data1[Tuesday]).

GoldSim rounds to the nearest integer when evaluating an array argument, so in this example, as long as the rounded value of X was between 1 and 7 inclusive, GoldSim would be able to evaluate the expression. If X evaluated to a number outside of that range, GoldSim would display a fatal error. Of course, X could change with time (or any other variable in your model).

This functionality can also be used with matrices. As an example, if Data2 was a matrix with the rows defined by the set "Days", and the columns defined by the set "Fruit" (with 3 entries), you could reference the following in an expression:

Data2[X, Y]

In this case, X would need to be an integer between 1 and 7, inclusive, and Y would need to be an integer between 1 and 3 inclusive. If X was 3 and Y was 2, it would return the item in row 3, column 2 of the matrix (i.e., Data2[Tuesday, Peaches] assuming Peaches was the second array label for "Fruit").

When using variables to reference array items, the following points should be noted:

Finally, when using this with matrices, you can use * as a wildcard. Using the example above,

Data2[*, Y]

would return column Y (a vector of Days). Similarly,

Data2[X, *]

would return row X (a vector of Fruit).

This ability to use variables when referencing array items is particularly powerful when using this feature in conjunction with array constructor functions.