LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find whether an array contains an element

Hi guys,

 

This seems like it should be really easy and obvious... but I want to search a number of 1D arrays for a particular element.

 

I want to output the other values in the array if the element is found, and nothing if it is not.

 

eg. Input:

1  2  3,

 

2  3  5,

 

5  3  7,

 

3  8  9

 

Search for: 5

 

Output:

2, 3, 7

 

Even a simple T/F output for each array would be ok, I could probably do the rest.

 

Thanks!

0 Kudos
Message 1 of 6
(3,759 Views)

Interesting!  That was a bit tougher than it looked at first.

Example_VI.png

 

I'm almost positive that this code will show up on the Rube-Goldberg Thread.   It works though.  (There almost has to be a way to do that in one loop)


"Should be" isn't "Is" -Jay
Message 2 of 6
(3,740 Views)

Jeff second for loop where you are using equal function and again building the array of boolean.

Without for loop its same

Message 3 of 6
(3,714 Views)

My solution, there's no removal of repeated numbers, i leave that to you.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 6
(3,701 Views)

Here's my solution, based on both of yours above, and the fact that each row contains only 3 elements. (If anyone's interested I'm using it to find nearest neighbours in a Delaunay triangulation)

I tried to make it simpler... but I may have just Goldberged this even further...

 

 

Thanks guys!

0 Kudos
Message 5 of 6
(3,671 Views)

MOI_maker wrote:

I tried to make it simpler... but I may have just Goldberged this even further...


You know that "index array" is resizeable, right? 😄

0 Kudos
Message 6 of 6
(3,658 Views)