Index of a value in an array
Index of a value in an array
(OP)
Hi,
I'm very new to Mathcad (12), I'm trying to find the index that a particular value appears at in an array. Even better I need to know what index of the element with the highest value is.
I hope that makes sense, a quick example just in case:
say the array = (0,3,9,5,2)
I want a function to return 2 (the index of 9).
Thanks in advance,
Iain
I'm very new to Mathcad (12), I'm trying to find the index that a particular value appears at in an array. Even better I need to know what index of the element with the highest value is.
I hope that makes sense, a quick example just in case:
say the array = (0,3,9,5,2)
I want a function to return 2 (the index of 9).
Thanks in advance,
Iain





RE: Index of a value in an array
as long as you have an array, (a matrix with 1 row & 5 cols) as you describe in your post, cols(array) should return 5. The function match(array) should return 2.
If you start with a vector (with 5 rows & 1 col) then use rows(vector) to get 5. match(vector) will return 2.
regards,
chichuck
RE: Index of a value in an array
match(max(array),array)
This will return a vector containing the index of the maximum value in array.
Peter
RE: Index of a value in an array
- Resource Center
- Quicksheet References
- Vector and Matrices
- Locating All Elements in an Array That Match a Condition.
Unfortunately, this particular example may not be for beginners. However, this may give you an idea what is require to solve this type of problem.
Good luck.