01-08-2016 10:03 AM - edited 01-08-2016 10:10 AM
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
01-08-2016 10:23 AM - edited 01-08-2016 10:24 AM
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.
01-08-2016 10:45 AM
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...
01-08-2016 10:55 AM
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.