Defining and Assigning Array Variables in a Script

The variables in your script can be defined as arrays (vectors or matrices). When defining a local script variable that is an array A collection of variables that share common output attributes and can be manipulated in GoldSim elements or input expressions. in a Variable Definition statement, or assigning a value to a script variable that is an array in a Variable Assignment statement, the Definition portion of the dialog expands to provide some additional options for defining the array:

If you are defining a vector A one-dimensional array., there are two choices in this drop-list:

Similarly, if you are defining a matrix A two-dimensional array., there are four choices in this drop-list:

Note: When you are specifying the "Item at index" (for a vector or matrix), or "Row at index" or "Column at index" (for a matrix), you do not have to enter a number. You can enter any scalar expression. GoldSim rounds the result to the nearest integer value. This allows you to define arrays by embedding Variable Assignment statements in loops (in which case these indices are often the loop counter variable).

The discussion above applies to assigning values to arrays in both Variable Definition statements and Variable Assignment statements. That is, both types of statements are used to assign values. It is important to understand, however, that the behavior of the two types of statements is different when assigning values to arrays.

To understand this, consider the following excerpt from a script, containing a Variable Definition statement, as well as a Variable Assignment statement (that references a previously defined variable):

Both X and Y are vectors. Line 3 assigns the value 4 to the second item of vector X. Line 5 assigns the value 2 to the second item of vector Y. The question is: since these statements only partially assign values to the vector (i.e., they only assign the second item), how do the statements affect the other items in the vector (that are not explicitly referenced)? The difference is as follows: