From 11:00 PM CDT Friday, May 10 – 02:30 PM CDT Saturday, May 11 (04:00 AM UTC – 07:30 PM UTC), 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: 

Delete duplicates numeric raw from 2D array

Solved!
Go to solution

Hello, I am new in LabVIEW, recently I need to build a new 2D array.

 

As the figure, I want to delete the duplicate raw from the 2D array.

 

Can anyone help me?

goal.png

0 Kudos
Message 1 of 6
(2,513 Views)

Well, you need to compare each row with all the rows already looked at, which can get very expensive once the array gets long. For small arrays, explicit comparison would be no problem. What have you tried?. For larger arrays, I would use a FOR loop and cast each row to a string and use variant attributes to check for duplicates. Much more efficient (logN vs. NxN).

 

Next time attach a simple VI containing typical default data. It makes it much more likely that somebody creates some code for you. What is the datatype of the array?

0 Kudos
Message 2 of 6
(2,503 Views)

@altenbach wrote:

For larger arrays, I would use a FOR loop and cast each row to a string and use variant attributes to check for duplicates. Much more efficient (logN vs. NxN).


Here's how that could look like. Make sure you understand how it works. 😄

 

(For an even better solution, come to my talk at NI Week 2019 :D)

 

VariantDuplicateRow.png

0 Kudos
Message 3 of 6
(2,499 Views)
Solution
Accepted by topic author antinhia

For completeness, here's a simple solution without variant attributes. Good enough for small arrays, but inefficient once the number of rows gets large. There are many other ways to do all that, of course, but they probably require more code (shift registers, case structures, etc.).

 

(Note That you cannot invert the logic and termination condition to avoid the NOT, because in the first iteration the inner loop iterates zero times and outputs a FALSE.)

 

I recommend the variant based solution above!

 

 

VariantDuplicateRowInefficient.png

 

 

You did not say what the datatype of the array is. If it is orange, you potentially need to worry about handling NaN, because they would throw a wrench depending on what you expect from the comparison. (Generally, NaN != NaN 🐵

 

Message 4 of 6
(2,479 Views)

Thanks a lot! I already finish my work, but I still have some quotations.

 

When I tried the solution 1, after I start the program the "error 1" happened.

 

And I tried the solution 2, I need to add the "And Array Elements".

array.png

 

0 Kudos
Message 5 of 6
(2,464 Views)

No, just right-click the equal comparison and change to "compare aggregates" comparison mode. No need for "and array elements". 🙂

 

Both versions run fine here, so to see what's wrong with your variant attribute solution, show us what you did. I am sure you overlooked something simple.

0 Kudos
Message 6 of 6
(2,459 Views)