Log in

View Full Version : counting consecutive values in an array



5ko
11-28-2012, 11:12 PM
Hello Everyone,
I need your help to count consecutive values in an array.
If you look at the file attached - there is an example.

1. a1:a38 - is the array and i would like to insert a formula that will be counting if there are more than 5 consecutive "ODD" occurences - the answer should be 8

2. e1: e38 - is my second array - and there i would like to insert a formula that will be counting more than 5 occurances ODD-EVEN-ODD-EVEN or EVEN-ODD-EVEN-ODD - the answer should be 9

Thanks!

5ko
11-29-2012, 11:51 PM
if 2.) is difficult to be done i would appreciate suggestions for 1.)

Admin
11-30-2012, 09:05 AM
Hi

For 1, this would work.

=MAX(FREQUENCY(IF(A1:A38="ODD",ROW(A1:A38)),IF(A1:A38<>"ODD",ROW(A1:A38))))

tfurnivall
12-04-2012, 03:49 AM
Hi sko

I'm having a problem understanding the true requirements of your second request. You say that you want the count of occurrences of the sequence of values "ODD/EVEN/ODD/EVEN" or "EVEN/ODD/EVEN/ODD".

Your suggested answer of 9 implies that overlapping occurrences are fine.

ie. the SEQUENCE "ODD/EVEN/ODD/EVEN/ODD" has two occurrences - the first is "ODD/EVEN/ODD/EVEN" and the second (which starts with the first EVEN) is
"EVEN/ODD'EVEN/ODD"

Using this as the basis for calculating, I come up with only 7 occurrences. The first is in cells E7:E10, and then there are sequences starting in E30, E31, E32, E33, E34 and E35. The sequences starting in E36, #37 and E38 are too short to qualify as true occurrences. It may be that you wanted consecutive sequences of more than 5 occurrences, in which case the singleton occurrence at E7 should be discarded giving only 6 (or 2 if you are actually counting the sequences of 5+).

Can you please clarify exactly what you are trying to do - this will help finding a solution!

Tony