anthonyjr2 Posted May 26, 2017 Share Posted May 26, 2017 (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: 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 May 30, 2017 by anthonyjr2 UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
benners Posted May 26, 2017 Share Posted May 26, 2017 They need to have the same number of columns. #include <Array.au3> local $array1[1][30] = [[0]] local $array2[1][30] = [[1]] _ArrayConcatenate($array1, $array2) _ArrayDisplay($array1) Link to comment Share on other sites More sharing options...
anthonyjr2 Posted May 26, 2017 Author Share Posted May 26, 2017 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= Link to comment Share on other sites More sharing options...
benners Posted May 26, 2017 Share Posted May 26, 2017 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) anthonyjr2 1 Link to comment Share on other sites More sharing options...
anthonyjr2 Posted May 26, 2017 Author Share Posted May 26, 2017 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= Link to comment Share on other sites More sharing options...
czardas Posted May 26, 2017 Share Posted May 26, 2017 (edited) You can also use _ArrayAttach($aTarget, $aSource, 2) to add more columns to a 2D array. This requires ArrayWorkshop.au3. Edited May 26, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
anthonyjr2 Posted May 30, 2017 Author Share Posted May 30, 2017 It turns out that transposing and then concatenating worked great! Problem solved. UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI= Link to comment Share on other sites More sharing options...
czardas Posted May 30, 2017 Share Posted May 30, 2017 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. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
anthonyjr2 Posted May 30, 2017 Author Share Posted May 30, 2017 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= Link to comment Share on other sites More sharing options...
czardas Posted May 30, 2017 Share Posted May 30, 2017 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. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now