ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I remove repeated elements in an array

just for the sake of different solution

aaa.png

ofcourse valid only for positive numbers in array.

Christian, Is it fast?????

 

0 Kudos
Message 11 of 38
(3,416 Views)

@Neos wrote:

Christian, Is it fast?????

Probably not, because with every iteration you compare the current value with every single value in the shift register array. N² comparisons for a size N input array. A 100x bigger array needs 10000x more comparisons!

 

Not tested.

Message 12 of 38
(3,408 Views)

OK Christian,

I think i got your point. ( i never thought that way ):smileysurprised:

Now i have one more idea, if i can insert 1 array subset function with index zero and length of array from lower shift register. That will only give me any array of limited elements so limited comparison but i will end up with an extra copy of array for array subset.

Am I right ?

So still not fast

bbb.png

 

0 Kudos
Message 13 of 38
(3,401 Views)

one more attempt

cccc.png

If array has zeros also then shift register comparison will start from -1.

0 Kudos
Message 14 of 38
(3,390 Views)

@Neos wrote:

one more attempt


This is getting better, however if the sorted input array starts with a zero, the output would be wrong. Right?

You can also save some array buffer allocations.

 

Also note that this idea would make things a bit simpler. 😄

0 Kudos
Message 15 of 38
(3,385 Views)

@altenbach wrote:

@Neos wrote:

one more attempt


This is getting better, however if the sorted input array starts with a zero, the output would be wrong. Right?

 


No, I edited my reply, use -1 in place on 0.Smiley Wink


 

You can also save some array buffer allocations.

 


Where am i missing??Smiley Surprised


 

Also note that this idea would make things a bit simpler. 😄


KudoedSmiley Very Happy

0 Kudos
Message 16 of 38
(3,378 Views)

Anyway, since you are getting close, here's my benchmark I wrote earlier, compairing 4 different code versions. Mine is pretty standard code and I suspect that the openG version is similar (not checked, because I don't have it). The main technique has been discussed many times in the past (e.g. here is my post from 2005).

 

Attached version is in labVIEW 2013, but I also attached a LabVIEW 9 version. Do you need older?

 

 

Message 17 of 38
(3,376 Views)

 


Neos wrote:  

No, I edited my reply, use -1 in place on 0.:smileywink:


 Then you will have a problem if the sorted array starts with -1. 😉

 


Neos wrote:

Where am i missing??Smiley Surprised


 

Note that you need two full sized arrays (1) the sorted array, (2) the initialized array.

 

If you look at my code, you will notice that I place the sorted array directly into the shift register. Since we always read from the unmodified section, there is no problem operating only on one single array.

0 Kudos
Message 18 of 38
(3,371 Views)

I am not able to open your VI ( 2009 version ).

It say LabVIEW error load 3, could not load front panel.

 

 

0 Kudos
Message 19 of 38
(3,365 Views)

@Neos wrote:

I am not able to open your VI ( 2009 version ).

It say LabVIEW error load 3, could not load front panel.


Well, it opens just fine back in 2013. Maybe there is a downconversion bug. What version are you using?

 

Here's LabVIEW 8.2 version. See if this works better.

Message 20 of 38
(3,360 Views)