LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

delete duplicated consecutive elements in array

Solved!
Go to solution

Hi

I am trying to make a vi that  will get an array and check for each 2 consecutive elements if they are the same - if yes delete only one of them and move on to the next couple and check again.

for example :

 input array :           16 2 67 128 10 10 42 55 10 10 10 10 22 33 10 03 22 55

output  should be  : 16 2 67 128 10  42 55 10  10  22 33 10 03 22 55

 

i will appreciate  any help

thanks

 

 

0 Kudos
Message 1 of 11
(3,395 Views)

See here

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 11
(3,389 Views)

Thanks but it is not what i need 

the input is:                                  1626 7128 1010 4255 1010 1010 2233 1003 2255 

the output from this function is :  1626 7128 1042 5522 3303 

and i need it to be :                      1626 7128 10 4255 10 10 2233 1003 2255 

from every  duplicated couple to take one 

 

thanks

 

 

0 Kudos
Message 3 of 11
(3,371 Views)

A simple FOR loop with a conditional output tunnel and a Feedback Node (or shift register) will do the trick.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 11
(3,357 Views)

Thanks to you 

but still not exactly what  I need because if I have Input 01 10 10 10 10 02

I get out put :                                                                   01 10 02

And I want to get                                                              01 10  10  02  

from every two consecutive numbers to get  one

(I know if it will be duplicated it would be an even number of times)

 

Thanks

0 Kudos
Message 5 of 11
(3,346 Views)

Hi nuvo,

 

so you want to keep a value

 IF x[n] <> x[n-1] OR x[n-1] == x[n-2]

?

(Well, my expression is most probably not correct, but it's your task to define your requirement anyway. 🙂 )

 

All you need to do is to define your requirement in the correct way…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 11
(3,338 Views)

esempio.png

This is one of many ways to accomplish what you need. Assuming that the input array has always an even number of elements.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 7 of 11
(3,337 Views)
Solution
Accepted by nuvo

@nuvo wrote:

but still not exactly what  I need because


Then just add a little more logic to keep an element if the previous was thrown out.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 11
(3,329 Views)

@GerdW wrote:

...

(Well, my expression is most probably not correct, but it's your task to define your requirement anyway. 🙂 )

 

All you need to do is to define your requirement in the correct way…


Ditto that!

 

Quoting myself;

 

"The first step in solving a problem is clearly defining what the problem is."

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 11
(3,310 Views)

Hey, 

What the use of that NaN at the input of Feedback initializer.

0 Kudos
Message 10 of 11
(252 Views)