LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check array if there is a duplicate value

Solved!
Go to solution

Built into LabVIEW is the Remove Duplicates From 1D Array.vim.  I also have a set of Array VIMs posted over on VIPM.IO.  It has a Remove 1D Array Duplicates.  If it is not sorted than it uses Sets and will return the Array with Unique values, and the Indices that were removed.  If the Array is sorted it will return the same values, but now will just loop through the array once.  OpenG has a similar function but it predated Sets and uses uses the Search 1D Array primitive.

Message 11 of 14
(265 Views)

@Hooovahh wrote:

Built into LabVIEW is the Remove Duplicates From 1D Array.vim. 


Removing duplicates is not the same as telling (via a simple Boolean output!) if all elements are unique or not. Of course we don't know the final reason of the OP for this. 😄

 

0 Kudos
Message 12 of 14
(248 Views)

@altenbach wrote:

@Hooovahh wrote:

Built into LabVIEW is the Remove Duplicates From 1D Array.vim. 


Removing duplicates is not the same as telling (via a simple Boolean output!) if all elements are unique or not. Of course we don't know the final reason of the OP for this. 😄


I mean yes you are of course correct. I should have said use the function I referenced, then if the indices of elements removed is empty, then you know there were no duplicates.  I guess with the native VIM you can look at the array size, and see if they are the same. If so you know there were no duplicates.

Message 13 of 14
(243 Views)

@davy.k wrote:

Could be a relevant edge case, though checking floating point numbers for equality is code smell and usually a bad idea IMO. I assumed that we're just using floating point in these examples because it's the default.


Yes, equal comparisons are somewhat dangerous for DBL, but in this case we are detecting true binary duplicates and if none are found, all elements are unique (...but some might be very, very similar). :D.

 

To decide if this is acceptable, we need to know much more about the actual use case.

Message 14 of 14
(241 Views)