maniootek Posted April 8, 2022 Posted April 8, 2022 (edited) Before I start code my own function to do that I am wondering if there is a ready function or UDF to add 2d array to another 2d array but to the "right" instead of to the "bottom" ? For example I have two 2d array which looks this way: first array: a1 | a2 | a3 b1 | b2 | b3 second array: a4 | a5 | a6 b4 | b5 | b6 both arrays has 3 colums and two rows I want combine this two arrays to get 2d array with 6 columns and two rows: a1 | a2 | a3 | a4 | a5 | a6 b1 | b2 | b3 | b4 | b5 | b6 I have very big arrays with multiple columns and I want combine it toghether this way. Anyone have any idea how to do it? Edit: Ok nvm, I think I got it: Func ArrayAddRight($Array1, $Array2) Local $aResult = $Array1 Local $rows1 = Ubound($aResult) Local $rows2 = Ubound($Array2) Local $cols1 = Ubound($aResult,2) Local $cols2 = Ubound($Array2,2) Local $cols = $cols1+$cols2 Local $rows = $rows1 if $rows2 > $rows1 then $rows = $rows2 ReDim $aResult[$rows][$cols] Local $counter for $i=0 to $rows - 1 $counter = 0 for $j=$cols1 to $cols - 1 $aResult[$i][$j] = $Array2[$i][$counter] $counter += 1 Next Next Return $aResult EndFunc Edited April 8, 2022 by maniootek
Nine Posted April 8, 2022 Posted April 8, 2022 @mandriospo You should pass your arrays with ByRef, especially if the arrays get larger. Otherwise the arrays are copied and can consume quite some time for nothing. maniootek 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
jugador Posted April 8, 2022 Posted April 8, 2022 (edited) Now to run this you need ArrayColInsert (version 2) expandcollapse popup#include <Array.au3> #include "ArrayInsertCol.au3" ;__ExampleA() __ExampleB() Func __ExampleA() Local $A_Array[][] = [['A1', 'A2', 'A3'], _ ['B1', 'B2', 'B3'], _ ['C1', 'C2', 'C3'], _ ['D1', 'D2', 'D3'], _ ['E1', 'E2', 'E3']] Local $B_Array[][] = [['A4', 'A5', 'A6'], _ ['B4', 'B5', 'B6'], _ ['C4', 'C5', 'C6'], _ ['D4', 'D5', 'D6'], _ ['E4', 'E5', 'E6']] ;~ insert at end __ArrayColInsert_V2($A_Array, UBound($A_Array, 2), $B_Array) _ArrayDisplay($A_Array, '$A_Array') EndFunc Func __ExampleB() Local $A_Array[][] = [['A1', 'A2', 'A3'], _ ['B1', 'B2', 'B3'], _ ['C1', 'C2', 'C3'], _ ['D1', 'D2', 'D3'], _ ['E1', 'E2', 'E3']] Local $B_Array[][] = [['A4', 'A5', 'A6'], _ ['B4', 'B5', 'B6'], _ ['C4', 'C5', 'C6'], _ ['D4', 'D5', 'D6'], _ ['E4', 'E5', 'E6']] ;~ insert from column 0 __ArrayColInsert_V2($A_Array, 0, $B_Array) _ArrayDisplay($A_Array, '$A_Array') EndFunc Edited April 8, 2022 by jugador
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