12-24-2008 05:33 PM
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
Solved! Go to Solution.
12-24-2008 06:01 PM
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.
12-24-2008 06:42 PM
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.
12-24-2008 10:10 PM
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
12-24-2008 11:15 PM
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.
12-30-2008 11:42 AM - edited 12-30-2008 11:44 AM
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
12-30-2008 12:12 PM
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. 😄
12-30-2008 04:54 PM - edited 12-30-2008 04:55 PM
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
12-30-2008 05:08 PM
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...
Anything is possible!
01-01-2009 12:24 AM
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