×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

find the element of an array

find the element of an array

find the element of an array

(OP)
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

RE: find the element of an array

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
 

RE: find the element of an array

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

Thanks again!
 

RE: find the element of an array

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

Thanks again.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources