09-22-2021 12:51 PM
I am trying to search an array that may or may not have multiple entries for what I am searching. I know for a fact there is 2 entries and the strings match, but the Search 1D Array is returning -1. The code works when only 1 matching entry is present. How do I get the system to return both (i have it in a while loop so it does run to the end of the search array) Is this normal function?
Solved! Go to Solution.
09-22-2021 01:02 PM
put it in a do while loop pass the index where the item was found into a shift register. Wire that or that plus 1 into the start index in the search 1D array. Stop the loop when you get a negative 1 for the index of element or'ed with a front panel abort button. Pass the list of indexes out of the loop with tunnel mode indexing and conditional turned on. set the conditional on that outgoing variable that is set to be false when the index is less than zero.
09-22-2021 02:33 PM
>> I know for a fact there is 2 entries and the strings match, but the Search 1D Array is returning -1
I believe you're doing something wrong to get that result. Can you show your code?
Also, there's a search function in the OpenG array tools that will return an array of indices containing all of the locations of the search string.
09-23-2021 01:52 AM - edited 09-23-2021 01:54 AM
@ljark wrote:
I know for a fact there is 2 entries and the strings match, but the Search 1D Array is returning -1. The code works when only 1 matching entry is present. How do I get the system to return both (i have it in a while loop so it does run to the end of the search array) Is this normal function?
It will always find the first one. If it returns -1 if there are multiple matches, something is wrong. I suspect that your while loop is not wired up correctly. What are the tunnel flavors (indexing, last value, etc.)? What determines the stop condition?
We can probably tell immediately what's wrong if you could attach a simplified VI and an array of strings. There are millions of ways to "put things in a while loop", and only a small fraction will result in reasonable code.
You can calculate from the number of iterations how many matches there are. If you also need their indices, follow the earlier advice.
09-23-2021 04:00 AM
Hello Ijark,
Hope you have got enough info on the solution for your issue (Looping/using VIPM Tools)
Also its always better to share your LabVIEW Code to guide you in better way.
Note:Try to sharing the LV with Lower Version LV2017/Lower
09-23-2021 07:18 AM
Thanks for the suggestions. I was not aware of the conditional tunnel so that will be very helpful in the future. Instead of manipulating with code. I am using LV2015. I was able to get it working now.
09-23-2021 07:18 AM
Try something like this:
09-23-2021 07:18 AM - edited 09-23-2021 07:51 AM
I am not aware of these OpenG tools yet so good to know, thank you. I will do some more research on these.