LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Locate repeated values

Solved!
Go to solution

Hello...

 

I need to build a VI to locate repeated values. If I have a column of values like below:

 

Index       Value

 

1                 0

2                 0

3                 0

4                 1

5                 1

6                 1

7                 1

8                 0

9                 0

10               1

11               1

12               1

13               0

14               0

15               0

16               0

17               1

18               1

19               0

20               0

21               0

22               0

23               0

24               1

25               1

 

I need that the VI locate a sequence of at least 3 repeated values (0 or 1) and name each of these sequences of repeated values as a "group", and provides me the index of each value cointaned in this "group".

 

Using the above values as example, the located groups would be:

 

Group 1 (Group of 0 values) - Indexes 1,2,3

Group 2 (Group of 1 values) - Indexes 4,5,6,7

Group 3 (Group of 1 values) - Indexes 10,11,12

Group 4 (Group of 0 values) - Indexes 13,14,15,16

Group 5 (Group of 0 values) - Indexes 19,20,21,22,23

 

Thanks for attention

 

Dan07

 

 

 

 

0 Kudos
Message 1 of 12
(3,441 Views)

Place the value from the second column into a shift register, then compare the current and previous values. If they differ, start a new group, else append to the current group.

0 Kudos
Message 2 of 12
(3,428 Views)

Here's a very simple example (LV8.5).

 


dan07 wrote:

Using the above values as example, the located groups would be:

 

Group 1 (Group of 0 values) - Indexes 1,2,3

Group 2 (Group of 1 values) - Indexes 4,5,6,7

Group 3 (Group of 1 values) - Indexes 10,11,12

Group 4 (Group of 0 values) - Indexes 13,14,15,16

Group 5 (Group of 0 values) - Indexes 19,20,21,22,23


I assumed you also wanted group6 (24, 25). If you don't want this, just remove the code to the right of the FOR loop and connect the indicator directly to the shift register.

 

I would also recomment that you start with zero as the first index. Simply remove the "+1" to do so.

Message 3 of 12
(3,416 Views)

Altenbach...

 

I assumed you also wanted group6 (24, 25). If you don't want this, just remove the code to the right of the FOR loop and connect the indicator directly to the shift register.

 

The only thing that I need to modify in the code is a way to specify that only sequences with 3 or more values will be called as a "group". In your example the groups found were:

 

Group 1 - 1,2,3

Group 2 -  4,5,6,7

Group 3 - 8,9

Group 4 - 10,11,12

Group 5 - 13,14,15,16

Group 6 - 17,18

Group 7 - 19,20,21,22,23

Group 8 - 24,25

 

The groups 3, 6 and 8 are not valid because they does not have at least 3 values. What I should change to take this?

 

Thanks very much for your attention

 

Dan07

0 Kudos
Message 4 of 12
(3,403 Views)

A minimal change would be to check the size of each group and retain it only if the size is sufficient.

 

Here's  quick rewrite that only retains groups with 3 or more elements.

0 Kudos
Message 5 of 12
(3,396 Views)

Altenbach

 

The code worked perfectly to me. But I have some questions about it:

 

The index array outside the For Loop, outputs the whole array and a single element (the first element of the array). Question: the outputed element its just to start the comparasion and feed the shift register with something?

 

Attached there are to images with the Case Structures Highlighted by red circles. I do not know how to set up the case structure to do something when the array size is 0,1 or 2 (since that the title of the case structure its just 0, and not 0,1 or 2). And another question: how did you set up the case structure to work when the array size its equal or greater than 3? 3, 4, 5, 6, 7, 8, 9......... Because I do not know how to set the "3..." to the title of the case structure.

 

Thanks for attention and happy new year to you and your family

 

Dan07

Message Edited by dan07 on 12-30-2008 11:44 AM
Download All
0 Kudos
Message 6 of 12
(3,326 Views)

dan07 wrote:

The index array outside the For Loop, outputs the whole array and a single element (the first element of the array). Question: the outputed element its just to start the comparasion and feed the shift register with something?


 If we don't initialize the shift register, it will contain the last value from the last run if we run the VI several times in a row. The initialization might not be needed in this particular case, but I did not study it in detail. Initially, I had slightly different code inside the loop where it made an important difference. 😉

 


dan07 wrote:

Attached there are to images with the Case Structures Highlighted by red circles. I do not know how to set up the case structure to do something when the array size is 0,1 or 2 (since that the title of the case structure its just 0, and not 0,1 or 2). And another question: how did you set up the case structure to work when the array size its equal or greater than 3? 3, 4, 5, 6, 7, 8, 9......... Because I do not know how to set the "3..." to the title of the case structure.


The case structure has two cases, the "3.." Meaning three and anything higher and "0,Default" meaning anything else. Just type "3.." to define that case. Do you have difficulty with that?

You could also deifine one case as "..2" and the other as "default". Same difference. 😄

Message 7 of 12
(3,316 Views)

altenbach wrote: 

 If we don't initialize the shift register, it will contain the last value from the last run if we run the VI several times in a row. The initialization might not be needed in this particular case, but I did not study it in detail. Initially, I had slightly different code inside the loop where it made an important difference.


 

 Ok. I understood what you said. In this case the element to initializes the shift register its quite important.

 

 


altenbach wrote:

The case structure has two cases, the "3.." Meaning three and anything higher and "0,Default" meaning anything else. Just type "3.." to define that case. Do you have difficulty with that?

You could also deifine one case as "..2" and the other as "default". Same difference. 😄


 

I did not know that "3.." has the meaning of "3 or greater". I have no difficult to type "3.." but I was not certain that only changing the title of the case structure will be enough, I did think that I need to do anything else. But now everything its clear.

 

The only question that I have is:  You said that "0" means "anything else". But if I want three different cases, one for "0", another to "3 or greater" and another to "anything else", in this case "0" will not act as "anything else", how I should set up the cases in this situation?

 

Thanks

 

Dan07

Message Edited by dan07 on 12-30-2008 04:55 PM
0 Kudos
Message 8 of 12
(3,293 Views)

dan07 wrote:

 Ok. I understood what you said. In this case the element to initializes the shift register its quite important.


 

 


dan07 wrote:

The only question that I have is:  You said that "0" means "anything else". But if I want three different cases, one for "0", another to "3 or greater" and another to "anything else", in this case "0" will not act as "anything else", how I should set up the cases in this situation?


No, the 0 is irrelevant here, you could even leave it out. What matters is that the case is defined as "default". Make one case "0", once case "3.." and a third case the default (right-click...make this the default case).

 

SImilarly...

 

  • you could have two cases "..2" and "3.." covering all possible cases (no default needed).
  • You could have 5 cases,
    1. default"
    2. "2..7"
    3. "20..25"
    4. "-100" 
    5. 244
  • and an all inputs that don't fit cases 2 through 5 will execute case 1. An input of 21 wound trigger case 3, 243 would trigger case 1 and 244 woud trigger case 5.

 

Anything is possible!

Message 9 of 12
(3,289 Views)

Altenbach...

 

I performed some tests using your suggestions (xx..xx, ..xx, xx..) and I understood how this case structure set up works. I have one final question: I need that each group identified, also shows if the group its made of "0" elements or "1" elements.

 

What is better, perform one comparasion for each element that feed the for loop and use this comparasion to change the dataflow using case structures, or,  after all the groups had been identified, use one of the indexes of each group to search in the array and return the element?

 

Thanks

 

Dan07

0 Kudos
Message 10 of 12
(3,261 Views)