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.
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.
04-01-2019 10:15 AM
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?
Solved! Go to Solution.
04-01-2019 10:35 AM
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?
04-01-2019 10:44 AM
@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)
04-01-2019 11:06 AM - edited 04-01-2019 11:11 AM
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!
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 🐵
04-01-2019 12:28 PM
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".
04-01-2019 12:35 PM - edited 04-01-2019 12:38 PM
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.