LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract just the unique rows from 2d array

Solved!
Go to solution

Here is a 2 minute modification that works with any row size and can be changed to any array input data type by simply changing the representation of the input array (Try DBL, CDB, U64, I8, etc.).

 

 

0 Kudos
Message 11 of 18
(2,186 Views)

@altenbach wrote:

 

Quote: "Hello, I'm sorry for my english. I have a 2D numeric array with thousends of rows and 2 columns. "

 

If the problem were posed differently, I would have posted different code. 😉


Sometimes I just need to read more carefully before jumping into a thread, especially when trying to comment on it well after midnight local time.  Thanks for sharing your code - I'll definitely have learned something once I figure out what it is doing.

 

In case anyone's curious, Altenbach's VI is a 20x improvement over my method, and over 300x faster than SteveM's simple direct method.

Message 12 of 18
(2,174 Views)

Hi all,

Sorry to reignite an old thread, but I'm working on a problem very similar to this right now and I'm wondering if any of you can help me out!

I have a very similar 2D array of integers, but instead of extracting the unique rows only, I'd like to keep the first instance of each duplicate row. In other words, I'd just like to delete the duplicates, without deleting the row that they're duplicating, if that makes any sense. My array is probably no more than 10 rows long, so a slow solution would work just fine.

Ex.

Input Array:
0 0

0 0 -> delete

0 1

1 0

0 1-> delete

2 0

2 1

 

Output Array:

0 0

0 1

1 0

2 0

2 1

 

Any tips you have would be helpful, thank you!

0 Kudos
Message 13 of 18
(1,984 Views)

Right now, I'm working with a slightly modified version of the original solution for simplicity (I'm relatively new to LabVEIW and didn't quite understand all of the components of the full solution).

Essentially I've attempted to take the output array from the solution that stevem181 posted, and search that array again for to see if the row has been added yet. If you're a stickler for efficiency I'm sure you're cringing at this point...

The issue I'm having is that when I test it with the following array I get an extra row that I don't want, and I'm not sure where it's coming from:

 

Input Array:

2 3

2 3

2 0

 

Output Array:

0 0

2 3

2 0

 

It seems the VI is working as intended, except for that pesky (0, 0) row. Additionally, the following occurs:

 

Input:

2 3

2 3

2 0
0 0

 

Output:

0 0

2 3

2 0

0 0

 

... I'm lost. Any ideas?

0 Kudos
Message 14 of 18
(1,957 Views)

Sorry, your VI is way too convoluted for my taste. 😉

 

See if this works for you instead. 😄

 

 

Download All
Message 15 of 18
(1,949 Views)

An interesting variation would be using variant attributes as follows:

 

 

Message 16 of 18
(1,944 Views)

That works great, thank you so much!

0 Kudos
Message 17 of 18
(1,923 Views)
Make sure you also understand it fully. 🙂
0 Kudos
Message 18 of 18
(1,913 Views)