## Dynamically Add a Row to a Matrix

#### Download

### Description

This model shows how you can use a matrix constructor function to join a vector to a matrix (i.e. join two arrays). The resulting matrix is larger than the original because we appended a vector ("Single_Row") to the end of the matrix ("Matrix_Original").

In this case, we start with a 10 x 4 matrix called "Matrix_Original" and a 1 x 4 vector called "Single_Row". This means we need to have the following Array Label Sets defined as follows:

- Array10: index range from 1...10
- Array4: index range from 1...4

When we append a row to the matrix, the dimensions change to an 11 x 4 matrix, which is called "Matrix_Added_Rows" in this model. The equation is as follows:

matrix(if(row <= getrowcount(Matrix_Original), Matrix_Original[row, col], Single_Row[col]))

The first part of this expression "matrix(..." is the matrix constructor. It causes us to iterate over each item of the matrix. Using an "IF" statement, we are able to control when we apply the values of the original matrix and when we apply the values of the single row.

### Additional Information

##### Keywords

array, constructor, vector, matrix

##### Categories

GoldSim Features & Capabilities, Arrays