Jump to content

switching array columns and rows


 Share

Recommended Posts

One way would be create a new array and transfer the values over to it.

Link to comment
Share on other sites

#include <Array.au3>

Global $avArray[3*4*5], $iCounter = 0

For $i = 0 To 3*4*5-1
    $avArray[$i] = Random(-200, 200)
Next

For $i = 0 To 2
    For $j = 0 To 4
        For $k = 0 To 3
            ConsoleWrite($avArray[$i*$j*$k] & @LF)
            $iCounter += 1
        Next
    Next
Next

ConsoleWrite('3 * 4 * 5 = ' & $iCounter & @LF)
$iCounter = 0

For $i = 0 To 4
    For $j = 0 To 3
        For $k = 0 To 2
            ConsoleWrite($avArray[$i*$j*$k] & @LF)
            $iCounter += 1
        Next
    Next
Next

ConsoleWrite('3 * 4 * 5 = ' & $iCounter & @LF)
Exit

If you'll look closely you'll see that you're accessing the array differently.

Link to comment
Share on other sites

@Authenticity: i dont really get what you are doing there tbh lol

@bchris01: trying that now

Question, how do you add to a specific array kind of like _ArrayAdd but for 2D arrays?

Edited by d0n
Link to comment
Share on other sites

Do a search for Array2D. There are a couple UDF's written for working with 2D Arrays.

Link to comment
Share on other sites

Thanks got it to work now, anyway to improve it?

$row = UBound($avArray,1)
$col = UBound($avArray,2)

Local $avArray2[2][2] = [[""],[""]]
ReDim $avArray2[$col][$row]
For $i=0 To $col-1
    For $j=0 To $row-1
        $avArray2[$i][$j] = $avArray[$j][$i]
    Next
Next
_ArrayDisplay($avArray2)
Link to comment
Share on other sites

Thats something like I was thinking. I dont think there is going to be a much faster way..

Link to comment
Share on other sites

  • 2 years later...

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