LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to match data in different array columns

Hey guys,

I am having a little trouble with this program of mine. What I want to do is have the user input some data, like a string, and then in an indicator it would show what corresponds with that particular data they entered when they hit a button. My program reads in tab delimited data from a text file and puts it into a 2D array, but that's where I'm stuck. I've searched around and am not sure how to extract and output the other column's data if given the other's as user input.

 

For example say I have this data in a tab delimited text file:

 

April                      Blue

May                      Red

June                      Green

 

Now I know how to read the text file and put it into a 2D array, but I'm stuck as far as going forward. For instance, if the user inputs April I would want my indicator to display Blue after they click a button. Or if the user inputs Blue I would want my indicator to display April and so on for all the data. So that if the user inputs any one row's value it would display the other column's value for that same row. I really don't think case structures would be the answer using standard parsing, because with my actual data I've got 100s of rows and that would be a lot of different cases at least as far as I know how to do it, and I'm not sure how to take out specific points of the 2D array and match it with another.

 

Any assistance anyone can provide is greatly appreciated. If anything is unclear I can try to better explain it. I just am not sure about how to do this extracting and matching, and couldn't find much out there for help.

 

Thanks!

 

 

 

 

0 Kudos
Message 1 of 18
(5,016 Views)

Use Index Array to pull out each column.

Then do a Search 1D Array to find the index of a matching element.

If you only match one column, you'll get an index for one result and -1 for the other.

Use the index obtained for the matching array to pull the matching element from the other array.

 

Give it a try and post where you get to.

Message 2 of 18
(5,001 Views)

Hi jf13,

 

Here is an example showing you two different ways to do that. The second example is a bit sneaky and specific to what you are trying to do, the first example is more generic. In the second example, I use concatenate string to build make I used constant data instead of reading from file, so you can integrate it into your own code. Let me know if you have any questions about how it works!

 

example.png

Message 3 of 18
(5,000 Views)

Thanks a lot for the help!

 

I've run into a snag though I believe. 

 

Here's what I've got so far.

 

labview picture.png

 

Now, the search function is storing all the data into the array indicator correctly. So that's all good, but anytime I give an input the output just says "Uncertain". I'm not sure why? If I understand the logic right, what it's doing is reading in the user's input and using that element and the array in order to find the index of that element and then outputs the matching index? It's a little fuzzy for me here. Once I hit run it browses for a file to use and I tell it which txt file I want, and it stores the loads of rows into two separate columns into a 2D array, but I guess it loses something past that?

 

Thanks again

0 Kudos
Message 4 of 18
(4,986 Views)

jf13 wrote:

Here's what I've got so far.

 

labview picture.png

 


You have a race condition.  Instead of using a local variable as an input to your loop (the All Rows local), use a wire directly from the Read Spreadsheet File.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 18
(4,982 Views)

Alright I have removed the local variable and wired the search function directly into my loop.

 

I still have the same result though. Hmm.

 

 

0 Kudos
Message 6 of 18
(4,978 Views)

Can you post the actual VI and an example data file?  That would be easier to debug than pictures.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 18
(4,972 Views)

One thing to be careful of is the Seach 1D array on strings requires an EXACT match.. so it's case sensitive and also prone to problems like: user added a space to the end.

 

From the string pallete, use "to lower case" or "to upper case" on both your file values and the user entered string.  this should remove the issue of case sensitive errors.

Message 8 of 18
(4,958 Views)

Will do thanks for pointing that out! Didn't even think about it.

0 Kudos
Message 9 of 18
(4,954 Views)

Here's a method without FOR loop.

 

Message 10 of 18
(4,974 Views)