LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search for all Elements in Array that Equal X

There was a recent Webinar about Variants and its many uses.  One of the uses it talked about was quickyly searching through an Array for all elements that equal X.  Granted, I could easily just throw down a For Loop and have a conditional logic, "Does X = Array Element."  But, the point of what I want to do is not have to parse through an Array of element size 700+.  The webinar mentioned that Variants can do this quicker.  Or is there another way to do this quicker than simple parse through entire array?  Suggestions would be greatly appreciated.

0 Kudos
Message 1 of 11
(4,000 Views)

If you are looking for 1 specific element, then you just need a shift register with the count.  If you are looking for multiple items, then use the Variant.


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
0 Kudos
Message 2 of 11
(3,987 Views)

For 700 elements, I doubt you will notice any difference between the methods mentioned. 

aputman
0 Kudos
Message 3 of 11
(3,984 Views)

Yes looking for multiple.  And when I say 700, it's really just a guess.  That's what I'm working with now, could be more.  Since the Array size is unknown, that's why I was thinking Variant.

So with a Variant, what does one do?  Change data to Variant and then search for value?

0 Kudos
Message 4 of 11
(3,975 Views)

@DailyDose wrote:

There was a recent Webinar about Variants and its many uses. ....  Or is there another way to do this quicker than simple parse through entire array?  Suggestions would be greatly appreciated.

Actually the "Data" does not become the Varient.  The Data Elements become "Attributes" of the Varient (The Varient value is often "Void" in these uses)
Now we are getting into esoteric areas about data theory

 

I won't go there since others have much better mastery of that arcane knowledge than I.  Simple entery level stuff can be found here and expanded a bit here

 

Varients use a "Red-Black" structure.  And of Course, there must be a better and quicker way!Smiley Surprised Just none of those geeky CS type nerds have discovered it yet to the best of my knowledge


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 11
(3,968 Views)

http://forums.ni.com/t5/LabVIEW/Darren-s-Weekly-Nugget-10-09-2006/td-p/425269

 

What type of data are you searching for?

aputman
0 Kudos
Message 6 of 11
(3,959 Views)

aputman wrote:

What type of data are you searching for?


That is a very good point.  The variant attribute name must be a string.  So you may have to convert your data elements to a string to properly use the variant.  Would have to do some benchmarks if that negates the search advantages you gain with the variant.


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
0 Kudos
Message 7 of 11
(3,952 Views)

So the question here then becomes, do I change my Array of data to Variant data?  I've attached the SubVI. It's in 2011 which is why I'm not using conditional indexing.  And Jeff, all I got to say is...Smiley Frustrated

0 Kudos
Message 8 of 11
(3,947 Views)

Since you don't actually have names to go with your data and you are dealing with numbers, I recommend to just stick with what you have.


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
Message 9 of 11
(3,938 Views)

After seeing your code.... no, this is not a place I would use a Varient.  (I did miss the webcast so I'll leave comments about that to others)

 

A Varient can be used for effiecntly retrieveing data (of any types as an attribute) from a unique key as a string.  Think "Ubber fast " Lookup Table.

 

In your code you want to retrieve Data by Value by searching data value.

 

Time to upgrade the LabVIEW version to get those nice conditional tunnels!  and move that comparison outside the loop!Smiley Wink (Hint index on the array of booleans out of "Equals")


"Should be" isn't "Is" -Jay
Message 10 of 11
(3,920 Views)