11-05-2013 03:06 PM
Hi I have an array
1,2,2,2,3,3,4,1,2,3,2
How can I remove the repeated elements to have just 1,2,3,4 . The order is not important. Could you please let me know how can I do it in labVIEW.
Thanks,
11-05-2013 03:33 PM
Step 1: Sort the 1D array
Step 2: wire into a for loop
Step 3: Place first value from array into output array.
Step 4: [inside for loop] Compare current value with previous value (shift register or feedback node)
Step 5: [inside for loop] If value does not equal previous (new value) add to the output array. (keep array between iterations using shift register)
11-05-2013 03:41 PM
Use OpenG, on the Array palette there is a Remove Duplicates From 1D Array.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
11-05-2013 05:07 PM
11-05-2013 05:54 PM - edited 11-05-2013 05:56 PM
11-05-2013 06:16 PM
11-05-2013 06:32 PM
@ouadji wrote:
This one is much faster (for large arrays)
I suspect that it could be made significantly faster for large arrays, because your search and delete is basically O(N²) (guessing), while the sort method is roughly O(NlogN). Delete from array is also very inefficient to use, because for every single delete operation, all higher elements need to be moved down (Arrays need to be contiguous in memory!). The last element in your array will get moved many times, depending on the number of duplicates. Way too much work!
Try to improve it! 😄
11-05-2013 06:52 PM
@apok :
Why complicate things when they can be simple? kudo.
@altenbach:
all higher elements need to be moved dow, the last element in your array will get moved many times, depending on the number of duplicates
thank you altenbach for your explanation
you're absolutely right, I had not looked at it from this angle. Understood!
Indeed, my code is very slow,
the code from Apok is much better and much faster.
11-05-2013 07:10 PM
ouadji wrote:the code from Apok is much better and much faster.
Mine is still orders of magnitude faster than both for large input arrays. 😄
For example for a size 50k input i get the following:
case 1: all elements are the same:
altenbach: 3ms
ouadji: 1300ms
apok: 25ms
case 2: 95% of elements are unique:
altenbach: 7ms
ouadji: 770ms
apok: 3800ms
11-05-2013 09:14 PM
@altenbach wrote:
ouadji wrote:the code from Apok is much better and much faster.
Mine is still orders of magnitude faster than both for large input arrays. 😄 ??
For example for a size 50k input i get the following:
case 1: all elements are the same:
altenbach: 3ms ??
ouadji: 1300ms
apok: 25ms
case 2: 95% of elements are unique:
altenbach: 7ms ??
ouadji: 770ms
apok: 3800ms
i want to be schooled....