Sign in to follow this  
Followers 0
Champak

Convert array

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



You need a transpose function. Something like


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0