From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract 2D-array value if contents match with a pattern array

 Hi everybody,

 

I am looking for an efficient way to extract in a 2D-array of strings (2 rows, several columns) the strings of the second row of the array according to matching of the first row data and another pattern array.

For sure I am not clear....

 

Maybe it is better with an example :

 

Pattern_Array_to_match = [blue, orange, green, yellow]

First_row_of_data = [blue, purple, black, white, green, orange, red, yellow]
Second_row_of_data = [cat, dog, fish, monkey, elephant, lion, eagle, dolphin]

I would like a VI that return [cat, lion, elephant, dolphin]...

 

Thanks

0 Kudos
Message 1 of 4
(3,548 Views)

Hi,

 

1 method ) If I understand correctly, I would get the first row of the original 2-D array as a one-d array.  The first row is the one you want to search on to return the value of the second row for the same column.

 

 Then use the find in 1-D array function to get the index numbers of the matches.  Then use the index numbers of the matches to get the values from the second row the original 2-d array with two rows of "paired" columns.

 

This may be a bit brute force 🙂  

 

 

second method) You could also do the whole enchilada using the for loop, index the original array, whenever you find a match in the first row, add the second row value to a results array. In this case, you can use the search one d array to search the pattern array with the value indexed in each turn of the loop.  However, if you need to keep the answers in order of the pattern, I would suggest indexing the pattern array first, then indexing the search array to find the first row value to get the second row value in the order of the pattern array.  

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 4
(3,529 Views)

I did this at the top of the picture. I think it works. However with a 1D array I cannot append the data in an Excel table... I do not understand why it as to be a 2D array...

 

Capture.PNG

0 Kudos
Message 3 of 4
(3,514 Views)

Hi,

 

That looks about right.   The labVIEW drivers can be very particular for excel dependingon how they were written.  If it is important you can always make a copy of that particular sub-vi (driver) and modify it for your own use ( the copy).  All depends on how much you can tolerate messing around with Excel Classes.

-------
Mark Ramsdale
-------
0 Kudos
Message 4 of 4
(3,505 Views)