Jump to content

Recommended Posts

Posted

Right now i have an array with 250 columns and 5 rows

i was wondering how would i go about switching them to 250 rows and 5 columns

Posted

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

Posted (edited)

@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
Posted

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

Posted

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)
Posted

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

  • 2 years later...
Posted

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

Why 2 lines here

Local $avArray2[2][2] = [[""],[""]]
ReDim $avArray2[$col][$row]

One line is sufficient

Local $avArray2[$col][$row]

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
×
×
  • Create New...