Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Confusion about rows,cols order in setarray

Feb
2
0
Hello,

the documentation about the order of rows,cols in setarray confuses me:

It says: You can define up to 4-dimensional arrays. For example, to define a 5-row by 10-column array:
Code:
setarray array1[5,10]

BTW: Its documented like this in TCMD 22.0, 25.0 and 28.0.

In my case I would like to have a 2-dimensional array with 4-rows (datasets) by 2-columns (Name, eMail). The following drawing illustrates the structure and my understanding of a two-dimensional array.

Code:
+------------------------------+-------------------------+
| Index | 1st dimension (Name) | 2nd dimension (eMail)   |
+-------+----------------------+-------------------------+
| 0     | Alice                | [email protected]          |
| 1     | Bob                  | [email protected]          |
| 2     | Barney               | [email protected]          |
| 3     | Fred                 | [email protected]    |
+-------+----------------------+-------------------------+

In fact, I have to define the array exactly the oposite way (cols,rows) to make it work!

Code:
@ECHO OFF
CLS
setarray /T:5 array[2,4]





:: Declaring values for the first dimension (i. e. Name)
set array[0,0]=Alice
echo %array[0,0]

set array[0,1]=Bob
echo %array[0,1]

set array[0,2]=Barney
echo %array[0,2]

set array[0,3]=Fred
echo %array[0,3]






:: Declaring values for the second dimension (i. e. eMail)
set array[1,0][email protected]
echo %array[0,0] = %array[1,0]

set array[1,1][email protected]
echo %array[0,1] = %array[1,1]

set array[1,2][email protected]
echo %array[0,2] = %array[1,2]

set array[1,3][email protected]
echo %array[0,3] = %array[1,3]





ECHO.
ECHO Number of dimensions of Array: %@arrayinfo[array,0]
ECHO Number of elements in the 1st-dimension of the array: %@arrayinfo[array,1]
ECHO Number of elements in the 2nd-dimension of the array: %@arrayinfo[array,2]
ECHO Total number of elements in the array: %@arrayinfo[array,5]
ECHO.




DO i=0 to %@DEC[%@arrayinfo[array,2]]
ECHO Value of ^%i: %i - %array[0,%i]           %array[1,%i]
ENDDO
unsetarray array

Gives the following output (as expected):

Code:
Alice
Bob
Barney
Fred
Alice = [email protected]
Bob = [email protected]
Barney = [email protected]
Fred = [email protected]


Number of dimensions of Array: 2
Number of elements in the 1st-dimension of the array: 2
Number of elements in the 2nd-dimension of the array: 4
Total number of elements in the array: 8


Value of %i: 0 - Alice         [email protected]
Value of %i: 1 - Bob           [email protected]
Value of %i: 2 - Barney        [email protected]
Value of %i: 3 - Fred          [email protected]

Or do I have a wrong understanding how does TCC arrange a two dimensional array?
 
Hello Vince,

Thank you very much for your response.

I'm afraid my understanding of rows and columns, as it has worked for relational databases for years, stands in the way of understanding multidimensional arrays. Am I right in assuming that I should think of a multidimensional array more as layers - as we know it from Photoshop or InDesign? In other words, should I think of the dimensions as layers with rows that I place "on top of each other" and then address the columns via the respective layers?

Nevertheless, I appreciate your much nicer style how to declare the columns of a row in one line.

Cheers.

M.
 
I have no Photoshop or InDesign experience. I am a mathematician and I think of a 2-D array the way a mathematician thinks of a matrix, first coordinate = row, second coordinate - column.

I would only use "row" and "column" for a 2-D array.

I would only use "layers" for a 3-D array, where there are many 2-D arrays in a stack.
 
If you do "set array[0,3]=Fred", then you are using the second dimension for your "row". You can call the dimensions anything you want, as long as you are consistent.
 
Back
Top