No BSD License  

Highlights from
findRuns.m

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.29 KB File ID: #22972

findRuns.m

by Richard Heitz

 

13 Feb 2009 (Updated 13 Feb 2009)

Returns indices of n consecutive numbers (you specify the number you want)

| Watch this File

File Information
Description

Accepts: a vector of numbers

Returns: the indices of n consecutive numbers of your specification

For instance, if you want to find the first instance of 10 consecutive 1's in a vector,

x = findRuns(vector,10,1)

Code may not be pretty, but it works and is quite fast.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
14 Feb 2009 Jos (10584)

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.

27 Feb 2009 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].

Please login to add a comment or rating.
Updates
13 Feb 2009

file name

Tag Activity for this File
Tag Applied By Date/Time
consecutive numbers Richard Heitz 13 Feb 2009 15:32:35
find Richard Heitz 13 Feb 2009 15:32:35

Contact us at files@mathworks.com