anthonyjr2

[Solved] Concatenating two column-based arrays

10 posts in this topic

#1 ·  Posted (edited)

I'm having an issue concatenating two arrays together that are of the format $array[1][30].

For example the _ArrayDisplay of each looks like this:

FJNFu0n.png

How can I concatenate two of these together? 

_ArrayConcatenate($arrOut, $arrClient)
If @error Then
    MsgBox(0, "Error", @error)
EndIf

This code is giving me Error 5, which states that there is a column mismatch. I'm guessing _ArrayConcatenate was made to be used with rows and not columns.

Anyone have any ideas on how to do this? Sorry if it's been asked before, but I searched and didn't find anything.

Edited by anthonyjr2

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites



#3 ·  Posted

Sorry if I didn't explain it well enough,

I want them to be side by side. As in if the first array has 1 row,10 columns and the second has 1 row,5 columns, the final concatenated array would just have 1 row,15 columns.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#4 ·  Posted

You could Redim the largest array to account for the extra columns in the smallest array and use _ArrayColInsert in a loop to add them together or something like below. Will only work work with 1D array, I think

#include <Array.au3>

local $array1[1][10] = [[0]]
local $array2[1][30] = [[1]]

_ArrayTranspose($array1)
_ArrayTranspose($array2)
_ArrayConcatenate($array1, $array2)
_ArrayTranspose($array1)
_ArrayDisplay($array1)

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

Hmm, that transpose solution seems promising. I'll try it when I get back to the office on Monday, it would be great if it works!


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You can also use _ArrayAttach($aTarget, $aSource, 2) to add more columns to a 2D array. This requires ArrayWorkshop.au3.

Edited by czardas

Share this post


Link to post
Share on other sites

#7 ·  Posted

It turns out that transposing and then concatenating worked great! Problem solved.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#8 ·  Posted

Yes it works. FYI - transposing the array is an extra step though. The method is suboptimal and you will notice some latency with larger arrays.

Share this post


Link to post
Share on other sites

#9 ·  Posted

3 hours ago, czardas said:

you will notice some latency with larger arrays.

I'm not too worried about that, the array is never going to be more than 20-30 elements.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#10 ·  Posted

17 minutes ago, anthonyjr2 said:

I'm not too worried about that, the array is never going to be more than 20-30 elements.

Worth pointing out because it might be relevant to someone in the future. Each transformation requires every element within the arrays to be overwritten. The solution is to write a function which adds the columns directly without first running twice around the block.

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