Jump to content

Convert array


Champak
 Share

Recommended Posts

i'm sure this has been asked for before, but i dont know exactly what to search for.

I get an array with a set amount of rows (4) and variable amount of columns. I want to convert the array and contents to a set amount of columns (4) and variable amount of rows. I hope I'm clear on that.

Thanks.

Link to comment
Share on other sites

You need a transpose function. Something like

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You mean something like this:

#include <array.au3>

Global $aTest[4][3] = [ [1, 2, 3], _
                                        [4, 5, 6], _
                                        [7, 8, 9], _
                                        [10, 11, 12]]

$aRot = ArrayRotate($aTest, 90)
_ArrayDisplay($aRot)

$aRot = ArrayRotate($aTest, 180)
_ArrayDisplay($aRot)

Func ArrayRotate($aArray, $iDeg) ;coded by UEZ 2012 build 2012-02-15
    If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;not an array
    If Not UBound($aArray, 0) = 2 Then Return SetError(2, 0, 0) ;not a 2D array
    If Mod($iDeg, 90) Then Return SetError(3, 0, 0) ;only 90° rotations allowed
    Local $i, $j, $k = 0, $l = 0
    Switch $iDeg
        Case 90, -270
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = 0 To UBound($aArray, 2) - 1
                For $j = UBound($aArray) -1 To 0 Step - 1
                    $aRotated[$i][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $k = 0
            Next
            Return $aRotated
        Case 270, -90
            Local $aRotated[UBound($aArray, 2)][UBound($aArray)]
            For $i = UBound($aArray, 2) - 1 To 0 Step - 1
                For $j = 0 To UBound($aArray) - 1
                    $aRotated[$l][$k] = $aArray[$j][$i]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
        Case 180, -180
            Local $aRotated[UBound($aArray)][UBound($aArray, 2)]
            For $i = UBound($aArray) - 1 To 0 Step - 1
                For $j = UBound($aArray, 2) - 1 To 0 Step - 1
                    $aRotated[$l][$k] = $aArray[$i][$j]
                    $k += 1
                Next
                $l += 1
                $k = 0
            Next
            Return $aRotated
    EndSwitch
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

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