# Convert array

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

##### Share on other sites

You need a transpose function. Something like

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:

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

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

##### Share on other sites

Yet another example.

I like the rotation UEZ

Spoiler

Misc Code Snippets:
Projects: SubnetCalc
Cool Stuff:

## Create an account

Register a new account