findRuns.m
Returns indices of n consecutive numbers (you specify the number you want)
Author: Richard Heitz
I agree, using strfind is a much more simplistic method. However, it fails to find ALL instances meeting a criterion. For instance, givin the vector [0 1 1 1 1 0 0], say you want to find instances of 3 or more 1's in a row.
Using strfind you'll get back [2 3]. Using findRuns, you'll get [2 3 4 5].
I agree, using strfind is a much more simplistic method. However, it fails to find ALL instances meeting a criterion. For instance, givin the vector [0 1 1 1 1 0 0], say you want to find instances of 3 or more 1's in a row.
Using strfind you'll get back [2 3]. Using findRuns, you'll get [2 3 4 5].
14 Feb 2009
findRuns.m
Returns indices of n consecutive numbers (you specify the number you want)
Author: Richard Heitz
Before evaluating the algorithm, you can improve the help section and add comments to the code. A proper help section consists of (1) an H1 line, (2) and explanation of the algorithm in plain language with a description of the input and output parameters, (3) and example, and perhaps (4) a See Also line.
As it is, "help finruns" returns nothing really useful, unless one take a closer look at the code.
The approach itself is also the result of translating pseudocode (C?) directly into matlab. Using a logical vector, combined with strfind easily returns the indices: Q = vector == value ; startidx = strfind(Q,[ 0 1]) ; etc ... which has been described many times on the newsgroup.
I feel honored (but also somewhat annoyed, if that is the right word for it) that you simply copied my whole RANDINTERVAL code into your submission, but you'd better stick to using
x = ceil(66*rand);
to select a random integer between 1 and 66 (inclusive)
I agree, using strfind is a much more simplistic method. However, it fails to find ALL instances meeting a criterion. For instance, givin the vector [0 1 1 1 1 0 0], say you want to find instances of 3 or more 1's in a row.
Using strfind you'll get back [2 3]. Using findRuns, you'll get [2 3 4 5].
Comment only
14 Feb 2009
findRuns.m
Returns indices of n consecutive numbers (you specify the number you want)
Before evaluating the algorithm, you can improve the help section and add comments to the code. A proper help section consists of (1) an H1 line, (2) and explanation of the algorithm in plain language with a description of the input and output parameters, (3) and example, and perhaps (4) a See Also line.
As it is, "help finruns" returns nothing really useful, unless one take a closer look at the code.
The approach itself is also the result of translating pseudocode (C?) directly into matlab. Using a logical vector, combined with strfind easily returns the indices: Q = vector == value ; startidx = strfind(Q,[ 0 1]) ; etc ... which has been described many times on the newsgroup.
Comment only