Jump to content

Combine columns in an array (Solved)


Recommended Posts

2D to 1D

**though if in a larger array you will probably have to use ArrayExtract to get the pieces you want, and ArrayColDelete before you ArrayColInsert the new column back in.

#include<array.au3>

local $arr[3][3] = [[1,4,7],[2,5,8],[3,6,9]]

_ArrayDisplay($arr)

_ArrayDisplay(stringsplit(_ArrayToString($arr , "|" , -1 , -1 , "|") , "|" , 2))

 

 

Edited by iamtheky
my awful explainer

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Try this.

#include <Array.au3>

; Create sample array
Local $aArray_Base[10][180]
For $i = 0 To UBound($aArray_Base) - 1
    For $j = 0 To UBound($aArray_Base, 2) - 1
        $aArray_Base[$i][$j] = $i & "-" & $j
    Next
Next
_ArrayDisplay($aArray_Base, "before")


Local $aColsToCombine[] = [171, 172, 173] ; Indexes of columns to combine.

; Combine columns
For $j = 1 To UBound($aColsToCombine) - 1
    For $i = 0 To UBound($aArray_Base) - 1
        $aArray_Base[$i][$aColsToCombine[0]] &= $aArray_Base[$i][$aColsToCombine[$j]] & " " ; Space used to separate data from each column.
    Next
Next

; Delete unwanted columns
For $j = UBound($aColsToCombine) - 1 To 1 Step -1
    _ArrayColDelete($aArray_Base, $aColsToCombine[$j])
Next
_ArrayDisplay($aArray_Base, "after")

 

Link to comment
Share on other sites

Malkey,

            That is exactly what I needed.    Just had to adjust one line to make it fit my needs perfectly.

Changed:

$aArray_Base[$i][$aColsToCombine[0]] &= $aArray_Base[$i][$aColsToCombine[$j]] & " " ; Space used to separate data from each column.

To 

$aArray_Base[$i][$aColsToCombine[0]] &="  "&$aArray_Base[$i][$aColsToCombine[$j]] & " " ; Space used to separate data from each column.

That gave me the correct spacing I needed.   Again Thank you

Link to comment
Share on other sites

  • xcaliber13 changed the title to Combine columns in an array (Solved)

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...