I would like to find index of a string in a MATRIX/Multi-dimensional array.
Does anyone know a function to get the same?
Index in a multi-dimensional Array/Matrix
Moderators: chulett, rschirm, roy
-
- Charter Member
- Posts: 199
- Joined: Tue Jan 18, 2005 2:50 am
- Location: India
Index in a multi-dimensional Array/Matrix
Shantanu Choudhary
-
- Charter Member
- Posts: 199
- Joined: Tue Jan 18, 2005 2:50 am
- Location: India
if you are refering to Index function then that wont help.WoMaWil wrote:there are several look into manual or help
I will explain my requirement. assume i have 3X3 matrix as
Code: Select all
Bill Jon Pam
Male Male Female
25 29 62
In my example I have mentioned the dimension (3X3); but in actual dimension is also unknown/variable.
The index function will return 7, assuming no spaces added for "Bill"/"Jon
Shantanu Choudhary
If your example was in 3x3 dynamic array:
You would use the LOCATE statement to search one row of the matrix for values. Upon finding the matching value, the statement returns the position in the array. That position can be used to reference the remaining rows. The statement has an if-then-else structure to let you handle it being found or not:
Code: Select all
example=""
example<1,1>="BILL"
example<1,2>="JON"
example<1,3>="PAM"
example<2,1>="MALE"
example<2,2>="MALE"
example<2,3>="FEMALE"
example<3,1>="25"
example<3,1>="29"
example<3,1>="62"
Code: Select all
LOCATE "JON" IN EXAMPLE<1> SETTING PSN THEN
GENDER = example<2,PSN>
AGE = example<3,PSN>
END ELSE
GENDER = "UNKNOWN"
AGE = 0
END
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
FIND may be easier to manage than LOCATE.
Or you could make a 1x9 matrix, copy from one to the other (using MAT keyword) and search that using LOCATE. If name found, add six to the where-found value to identify the element number of the desired age.
Or you could MATBUILD a nine-element dynamic array.
There are even more possibilities, you should be well under way with just these and those of the other posters.
Or you could make a 1x9 matrix, copy from one to the other (using MAT keyword) and search that using LOCATE. If name found, add six to the where-found value to identify the element number of the desired age.
Or you could MATBUILD a nine-element dynamic array.
There are even more possibilities, you should be well under way with just these and those of the other posters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.