Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index of a value in an array

Status
Not open for further replies.

shmmeee

Computer
Oct 21, 2005
1
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
 
Replies continue below

Recommended for you

shmmeee,


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
 
Match is the correct function, however the correct format is:

match(max(array),array)

This will return a vector containing the index of the maximum value in array.

Peter
 
You may find in your manual or in the software, sample problems that may help you with this task. For example, go to:
- 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor