# Appending A Multi-Dimensional Array

## Recommended Posts

I am having difficulty with using the append function with a 2-dimensionall array.  I am not sure I am referring to the array correctly in the function.  The "Seconds" and "PressureSetPoint" are two variables I want to store at the end of the existing array.

MyArray.append([seconds][PressureSetPoint])

When I run the function, I receive the error,

C1060 Improper number of parameters:

```global MyArray
global Seconds
Global SecondsStep
global PressureSetPoint
global PressureSetIncrement

MyArray = {{0,0}} // set first index in array to zero
Seconds = 0
SecondsStep = 5
PressureSetPoint = 30
PressureSetIncrement = 2

for (Private.CounterB = 1, CounterB < 5, CounterB++)

MyArray.append([Seconds][PressureSetPoint])
Seconds = Seconds + SecondsStep
PressureSetPoint = PressureSetPoint - PressureSetIncrement

endfor
```

Thank you for the help,

-Joe

##### Share on other sites

That is syntactically incorrect.  [] really are only used for subsetting, and you aren't subsetting.  If you were appending a scalar, you could use {} notation to build the row, but since you have variables you'll have to do it manually.  Basically this:

private temp = seconds   // sets the [0][0] element

temp[0][1] = pressureSetPoint

MyArray.append(temp)

##### Share on other sites

• 3 weeks later...

I am still totally failing at my effort to append a 2-dimensional array.  I can't even find where in the manual I originally found a reference to the use of MyArray.append.  In your example above, you show adding a single value. But, I think what is needed is to sent both the values in a column at the same time.  Otherwise, your 2D temp array may only add one of the values at the bottom row, and 0 to the upper row.  Then, when you attempt to set the upper row, you just append another index location with 0 at the bottom row and your value to the upper row.

Can you provide an example that appends two values to the end of a 2D array?

Also, can you please refer me to the chapter in the manual that talks about the MyArray.append function?  I have not been able to find it again.

Thank you very much for the help,

-Joe

##### Share on other sites

private temp = {{0,1}}

temp.append({{3,4}})

That's the static way and results in a 2x2 array.  If you want variables though what I did in my last post is correct.  It adds a single row, containing two columns to the end of myArray.   My example does not show adding a single value, it shows adding a single variable that is a 1x2 array.

global myArray

private temp = 1  // sets the [0][0] element

temp[0][1] = 2

MyArray.append(temp)

temp[0][0] = 3

temp[0][1] = 4

myArray.append(temp)

The above, assuming myarray is empty to start, will end up with a 2x2 array: {{1, 2}, {3, 4}}

The section on append is 5.10, but it doesn't say much.  Append() simply adds a new row to the end and puts the value there.  If the value you append() has multiple columns, then the result has multiple columns.