LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 1D Array when multiple results may be in array

Solved!
Go to solution

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?

 

 

0 Kudos
Message 1 of 8
(194 Views)
Solution
Accepted by topic author ljark

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.

0 Kudos
Message 2 of 8
(183 Views)

>> 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.

jcarmody_0-1632339156332.png

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 8
(148 Views)

@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.

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 8
(113 Views)

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

Pazhanivel Thiruvenkadam,
CertifiedLabVIEWArchitect|| CertifiedTestStandDeveloper,
Currently able to Access LV2015&LV2017
0 Kudos
Message 5 of 8
(102 Views)

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.  

0 Kudos
Message 6 of 8
(80 Views)

Try something like this:

 

Dobrinov_0-1632399455852.png

 

"Good judgment comes from experience; experience comes from bad judgment." Frederick Brooks
0 Kudos
Message 7 of 8
(79 Views)

I am not aware of these OpenG tools yet so good to know, thank you.   I will do some more research on these.

0 Kudos
Message 8 of 8
(78 Views)