LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 2D array for 2 matching criteria

Solved!
Go to solution

I have an array populated with X,Y,Z scatter plot data such that there are 3 columns and as many rows as there are entries into this array.  There is no two entries that have an identical X,Y combination.  I would like a VI that accepts user input for X and Y and returns both the Z value and the row index of that entry.  Search 1D array does not work because the array is 2D, and I am having trouble coming up with an elegant way of stepping through the array and examining the X and Y entries to obtain the Z entry and its row index.

 

Using LabView 2016 64bit, any help is appreciated, thank you.

0 Kudos
Message 1 of 10
(2,838 Views)

And help from you would also be appreciated -- best would be code (a file ending in .vi) that you've written that does/does not work + a data file showing the type of data you are describing (so we can test our own algorithms).  If you want us to do your work for you, at least help a little bit ...

 

Bob Schor

0 Kudos
Message 2 of 10
(2,815 Views)

convert into spreadsheet string via indexing for loop for the X & Y, will give you a searchable 1D string-type index array, do the same for your X & Y, build them into array before conversion to create the element to be searched, then use the search 1D array.

CY (expired CLAD)
0 Kudos
Message 3 of 10
(2,801 Views)

Is the array pretty much static or is it changing often? How big is the array (#of rows)? What is the datatype (DBL? integer?)? What are the performance requirements? Are the x and y columns sorted in some way?

 

For performance, I would probably convert to variant attributes by casting the first two elements into a binary string to be used as name and having a cluster or flattened string of the the z and row index as value. 

 

Please attach a small VI containing typical data (e.g. as diagram constant). and I probably can make an example in a few minutes.

0 Kudos
Message 4 of 10
(2,772 Views)

Sorry! Had a .vi, forgot to attach it... I have further explanation of what I've tried and my thought process within the comments of the block diagram.  That .vi is attached to this comment.

0 Kudos
Message 5 of 10
(2,770 Views)

Two quick comments:

  • You don't need to wire N when autoindexing.
  • There is absolutely no reason for these local variables.
  • Why is the array orange if you only have integers?
0 Kudos
Message 6 of 10
(2,765 Views)

Thank you for letting me know about auto-indexing N, I have mostly worked with while loops in LabView and not for loops as much.

You are right that the local variables are not needed how the VI is set up currently, I was trying (and failing) at multiple different solutions and attempting to not necessarily delete any of them in case an idea with one solution led to a breakthrough with an older one.  That led me to just use local variables everywhere and I would clean up my solution once I found one, but since I posted my file that only examined 2 things I tried, it is silly to have kept the local variables the way I did.

 

In my real data set, I have x and y values that are not only integers.

 

I have corrected those points on my sample code and re-attached to this comment.

0 Kudos
Message 7 of 10
(2,759 Views)
Solution
Accepted by topic author ryancam

Here's what I had in mind (of course you probably want an event structure to avoid polling in the second loop. This is just a draft):

 

FindZ.png

 

 

Message 8 of 10
(2,758 Views)

@altenbach wrote:

 

For performance, I would probably convert to variant attributes by casting the first two elements into a binary string to be used as name and having a cluster or flattened string of the the z and row index as value. 

 


For an even more elegant solution, come to my 2019 NI Week presentation in May. 😄

0 Kudos
Message 9 of 10
(2,752 Views)

@ryancam wrote:

 

In my real data set, I have x and y values that are not only integers.

 


Depending on where the data is coming from, equal comparison on floating point values can be very dangerous. You probably need to built some protection into it.

 

Also, if the xy coordinates are arranged in any kind of regular pattern (e.g. a scanned grid with x0, dx, y0, dy), more efficient solutions are possible. You could even do bilinear interpolation if there is no exact xy match.

0 Kudos
Message 10 of 10
(2,746 Views)