Showing results for 
Search instead for 
Did you mean: 

Search 2D array for row based on multiple inputs

Go to solution



I would like to extract the rows from the "Input Array" based on the "Search Array" and given "Column Index".


In the example given, a new array given by rows 1 and 2, extracted from the "Input Array", will be the desired match.  Therefore, the output array will be 2 rows given by Row 1 and Row 2 of the "Input Array".


Any help to get started on this is sincerely appreciated!




0 Kudos
Message 1 of 7
Accepted by hiNI

See if this works for you. (there are a few other ways to do it of course)





(In the more general case, you might want to trim whitespace and do other cleanup, etc.)


Message 2 of 7

Of course the above "solution does not scale well, because it would need to be rewritten if the number of matched columns is different from 3. It also assumes that the input is correct, e.g. that the two lower arrays have the same size. To guarantee equal size, I would probably use an array of clusters for the secondary inputs, where each cluster contains an index and string, for example. 

Message 3 of 7



I love the simplicity of your solution.  If the "Column Index" array size is changed from 3 to 5, I will have to manually change the index array size in your solution.  Is there a more dynamic solution possible given the requirement of automatically updating the index for scaleability?  The lower arrays are given to always be the same size.  Thanks again!

0 Kudos
Message 4 of 7
Accepted by hiNI

You could do something as follows:




(or just autoindex on both your arrays (no clusters) on the onner FOR loop and the shorter one wins)

Message 5 of 7





0 Kudos
Message 6 of 7

I am not sure why "term 1" is an array, but if you want to filter out rows that match term 1 AND term 2, just do e.g. as follows:





First term check if  the element in the first column is "1" and the second term checks if the element in the second column is in range.


You might want to specify which columns should be checked for term 2. You could add another index control (not shown).


(Next time when you attach a VI, please make sure all controls have typical default data so we can test.)


Message 7 of 7