LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Zekasa

Search 1D array with all the indices of the matched elements

Status: New

Hi,

 

 the "Search 1D array" function returns only the index of the fist item found. However some times, it is needed to get all the indices of the elements that match the element the we are searching for. I think it will be nice if this vi returns all the indices that match the element we are looking for.

 

g.gif   

 

to become like this

 

srcharay.gif

14 Comments
Darin.K
Trusted Enthusiast
You really need to be more careful posting code like that so soon after a coding challenge! 🙂
EngrStudent
Active Participant

So Donald Knuth spent a lot of time thinking through and documenting the provably best ways to search.

https://www.amazon.com/Art-Computer-Programming-Sorting-Searching/dp/0201896850

 

 

Would an "ideal" version of "return matching indices of array" be structured like a Knuth-search?

crossrulz
Knight of NI

The Search 1D Array assumes your array is not sorted.  Therefore, you are left with only being able to do a simple linear search.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
AristosQueue (NI)
NI Employee (retired)

crossrulz wrote:

> The Search 1D Array assumes your array is not sorted. Therefore, you

> are left with only being able to do a simple linear search.

 

Bingo. If you want to search with a sorted assumption, check out

     vi.lib\Array\Search Sorted 1D Array.vim

in LV 2019 or later. It's not in the palettes... yet. 😉