LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What does the Search 1-D array vi return with more than one match?

The Search 1D Array vi is supposed to return -1 if no match is found. Does it provide a unique output for the case where more than one match is found? If not, what's an easy way to search a 1D array and flag >1 matches?

Thanks,

Jeffrey Bledsoe
Jeffrey Bledsoe
Electrical Engineer
0 Kudos
Message 1 of 7
(3,175 Views)
The "Search 1D Array" function will only return the index of the first instance of the search item.

If you want to find all matching indexes, place the search function in a loop and pass the "Index of Element" terminal through a shift register to the next iteration of the loop and connect it to the "Start Index" terminal, but increment it by 1. This will search the rest of the array.

Take all the indexes of mathing elements and build into an array and pass that out of the loop.

The attached example shows this.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 7
(3,173 Views)


@Ed Dickens wrote:
The "Search 1D Array" function will only return the index of the first instance of the search item.

If you want to find all matching indexes, place the search function in a loop and pass the "Index of Element" terminal through a shift register to the next iteration of the loop and connect it to the "Start Index" terminal, but increment it by 1. This will search the rest of the array.

Take all the indexes of mathing elements and build into an array and pass that out of the loop.

The attached example shows this.

Ed


Ed,

I finally got to a PC with LV 7.1. I'm using LV 5.1 and I don't believe I can use the "stop if" option in the while loop. I tried the "continue looping" option with >= 0 as the condition. It works except I also get -1 as the last match. Do you know how I could execution of the last iteration or would I just have to ignore the -1 entry in the matrix?

Thank,

Jeff
Jeffrey Bledsoe
Electrical Engineer
0 Kudos
Message 3 of 7
(3,133 Views)


Ed,

I finally got to a PC with LV 7.1. I'm using LV 5.1 and I don't believe I can use the "stop if" option in the while loop. I tried the "continue looping" option with >= 0 as the condition. It works except I also get -1 as the last match. Do you know how I could execution of the last iteration or would I just have to ignore the -1 entry in the matrix?

Thank,

Jeff




Well the -1 is required as it is the termination criteria for the loop no way to skip that as you don't know beforehand that there won't be any more instance. So what I usually do in such cases is wiring out the loop iteration value and use it as input to the Resize Array function to effectively remove the last element. The new Delete Array node in LabVIEW 6 and higher could also do the same as by default it removes the last element in an array.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 7
(3,129 Views)
Rolf,

Okay, I used Reshape Array, wired i out to it, and it works.

Thanks for the help.

Jeff
Jeffrey Bledsoe
Electrical Engineer
0 Kudos
Message 5 of 7
(3,122 Views)
I cant open "Search Complete Array.vi" in my version of Labview. Could you please post a copy of the block diagram. Thank you.

Don McCurnin
0 Kudos
Message 6 of 7
(2,985 Views)

Here's a picture of the block diagram

Message Edited by AndrewAlford on 01-18-2006 01:24 PM

Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
0 Kudos
Message 7 of 7
(2,975 Views)