Sign in to follow this  
Followers 0
Champak

Concatenate multidimensional array

4 posts in this topic

Is this possible, or do I just have to redim the first array and write the second one in through a loop?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes, and yes (that's one way to go).

Probably want lots of error handling to make sure their dims line up.

Simple example

#include <array.au3>
Local $array1[2][2]=[[1,2],[3,4]]
Local $array2[2][2]=[[5,6],[7,8]]

For $i = 0 To UBound($array2)-1
    ReDim $array1[UBound($array1)+1][UBound($array1,2)]
    For $j = 0 To UBound($array2,2)-1
        $array1[UBound($array1)-1][$j] = $array2[$i][$j]
    Next
Next
_ArrayDisplay($array1)



not sure why this would ever be a case, but why not:

#include <array.au3>
Local $array1[2][2]=[[1,2],[3,4]]
Local $array2[2][3]=[[5,6,7],[8,9,0]]

For $i = 0 To UBound($array2)-1
    ReDim $array1[UBound($array1)+1][UBound($array1,2)]
    If UBound($array1,2)<UBound($array2,2) Then
        ReDim $array1[UBound($array1)][UBound($array2,2)]
    EndIf
    For $j = 0 To UBound($array2,2)-1
        $array1[UBound($array1)-1][$j] = $array2[$i][$j]
    Next
Next
_ArrayDisplay($array1)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Your route is a little different from how I was going to do it. I was just going to redim it once and then loop through everything. Ill try both ways to see which is faster. Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes, one redim would be quicker (when tons of data to concat)...just easier (conceptually) to increase by one each time...example with only one redim:

#include <array.au3>
Local $array1[2][2]=[[1,2],[3,4]]
Local $array2[4][2]=[[5,6],[7,8],[8,9],[0,1]]

ReDim $array1[UBound($array1)+UBound($array2)][UBound($array1,2)]
For $i = UBound($array1)-1 To UBound($array1)-UBound($array2) Step -1
    For $j = 0 To UBound($array1,2)-1
        $array1[$i][$j] = $array2[$i-UBound($array1)+UBound($array2)][$j]
    Next
Next
_ArrayDisplay($array1)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0