# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Search 2D array for row based on multiple inputs

Hello,

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!

Thanks,

hiNi.

Message 1 of 7
(2,475 Views)
Solution
Accepted by hiNI

## Re: Search 2D array for row based on multiple inputs

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
(2,461 Views)

## Re: Search 2D array for row based on multiple inputs

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
(2,449 Views)

## Re: Search 2D array for row based on multiple inputs

Hello,

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!

Message 4 of 7
(2,444 Views)
Solution
Accepted by hiNI

## Re: Search 2D array for row based on multiple inputs

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
(2,433 Views)

Message 6 of 7
(1,484 Views)

## Re: Search 2D array for row based on multiple inputs

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
(1,437 Views)