Jump to content

How do I use the "search 1D array" primative?


Recommended Posts

Umm, you have a 1D array of something (e.g. floating point numbers) and you have a single element (e.g. a value) that may or may not be in the array. You wire the array to the array input, the elment (value) to the element input, you get out -1 if value wasn't found in the array or the index (i.e. the position within your 1D array starting at 0 for the first element in the list up to N-1 where N is the length of the array. If you want to limit your search to start not at the first element but somewhere in the middle of the array you wire the starting index (counting from zero) into the start index input. It works, albeit in a not very scalable way because it can't assume that the elements are ordered (or indeed are sortable at all). There's really not a whole lot one can say about it.

Link to comment

gb119 you have more patience than me. Copied from the LabVIEW help.

Searches for an element in a 1D array starting at start index. Because the search is linear, you need not sort the array before calling this function. LabVIEW stops searching as soon as the element is found.

You cannot use this function to retrieve the index of a value that is not an element of the array. For example, if you have an array of two elements (0.0 and 1.0), this function does not find the index of the value 0.5, as that value is not an element of the array. Use the Threshold 1D Array to find a fractional index.

This function only finds a string if the element you specify matches an array element exactly. For example, if you have an array of two elements (upper limit and lower limit), this function does not find the index of the value limit, because limit does not match an array element exactly. To search a string for any occurrence of a regular expression, such as in the previous example, use the Match Regular Expression function.

Link to comment

I most often use it when I have an array of booleans or cluster of booleans( in which case I also use cluster to array function) and these are on the front panel and I want to trigger different events or conditions when each one of them is clicked. I use search 1d array function to determine if the boolean control is clicked. If index returned it not -1 I use case structure to define what I want to do.

I just tried to give an example of where this function could be used. Its a powerful function and could be used in many ways. Just use your imagination

Link to comment
  • 2 weeks later...

Back for more homework help?

It sounds like you don't have much programming experience, so it's not clear what kind of answer you are expecting beyond what has already been said. The only other thing I will add is to not use this to search an array of floating point values. If you do not understand why that is, I'd suggest starting here: http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary

Link to comment
  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.