Jump to content

Concatenate multidimensional array


Champak
 Share

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...