cancel
Showing results for 
Search instead for 
Did you mean: 

How can I remove repeated elements in an array

Neos
Active Participant

Re: How can I remove repeated elements in an array

Message contains an image

just for the sake of different solution

aaa.png

ofcourse valid only for positive numbers in array.

Christian, Is it fast?????

 

altenbach
Knight of NI

Re: How can I remove repeated elements in an array


@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.

Neos
Active Participant

Re: How can I remove repeated elements in an array

Message contains an image

OK Christian,

I think i got your point. ( i never thought that way )Smiley Surprised

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

 

Neos
Active Participant

Re: How can I remove repeated elements in an array

Message contains an image

one more attempt

cccc.png

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

altenbach
Knight of NI

Re: How can I remove repeated elements in an array

Message contains a hyperlink

@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. Smiley Very Happy

Neos
Active Participant

Re: How can I remove repeated elements in an array

Message contains a hyperlink

@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. Smiley Very Happy


KudoedSmiley Very Happy

altenbach
Knight of NI

Re: How can I remove repeated elements in an array

Message contains a hyperlink Message contains an image Message contains an attachment

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?

 

 

altenbach
Knight of NI

Re: How can I remove repeated elements in an array

 


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. Smiley Wink

 


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.

Neos
Active Participant

Re: How can I remove repeated elements in an array

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

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

 

 

altenbach
Knight of NI

Re: How can I remove repeated elements in an array

Message contains an attachment

@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.