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!

find the element of an array

Status
Not open for further replies.

pagheca

Mechanical
Nov 27, 2005
31
Hi,

I'm looking for the simplest way to find the index of the element of a vector that is closer to a given value.

Suppose the vector is f[i:=i^2 and the value V:40 .

The solution is i=6 as 6^2=36. How to find that i value? Do there is any function doing that? Do you know any trick using the programming?

See attachment for an attempt to solve it (not working.

regards and thanks in advance
 
Replies continue below

Recommended for you

You can do this without programming. Using the variables in your sheet:

Error:= vectorize abs(f-v.LO)
Index:= match(min(Error),Error)

Vectorize is a function on the matrix toolbar.

Peter
 
thanks very much, Peter. A very smart solution.
However, the result is a vector itself. How to convert it to a number?

Thanks again!
 
got it: I have to specify the index, of course... I was confused by the fact it was a one element vector!

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor