Jump to content

Recommended Posts

Posted (edited)

I needed to rotate or invert a 2D array (Make the columns rows and the rows columns). The reason I needed to do this is my array was built in the column direction but excel has a limit of about 250 columns(Xp) so in order to put my array into excel in needed to invert the array. I couldn't find anything in the help that did this for 2D arrays nor in the forms so I would like to post this incase someone ever needs to do this.

#include <Array.au3>

Dim $a1[4][4]=[[1,2,3,4],[5,6,7,8],[9,10,11,12], [13,14,15,16]] ; First array
_ArrayDisplay ($a1)
_ArrayInvert ($a1)
_ArrayDisplay ($a1)

Func _ArrayInvert (ByRef $Array1)   ;Rotates or inverts the array so columns become rows and rows columns
    Local $a1Rows = Ubound($Array1, 1)
    Local $a1Columns = Ubound($Array1,2)
    Local $Output [$a1Columns] [$a1Rows]
    For $y = 0 to $a1Rows -1
        For $x = 0 to $a1Columns -1
        $Output [$x][$y] = $Array1 [$y][$x]
        Next
    Next
$Array1=$Output
EndFunc

Edit: I hit enter and it posted a little premature...

Edited by Yokes9

I suck at programming... But I try really hard! :imwithstupid:

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
  • Recently Browsing   0 members

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