Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!f5g2000vbm.googlegroups.com!not-for-mail
From: Luna Moon <lunamoonmoon@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: how to find the kth-element in each consecutive run of numbers?
Date: Wed, 3 Feb 2010 19:23:42 -0800 (PST)
Organization: http://groups.google.com
Lines: 26
Message-ID: <8a256245-dc72-4fb2-a05e-02b9829bbb39@f5g2000vbm.googlegroups.com>
NNTP-Posting-Host: 199.89.103.11
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1265253822 25537 127.0.0.1 (4 Feb 2010 03:23:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 4 Feb 2010 03:23:42 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: f5g2000vbm.googlegroups.com; posting-host=199.89.103.11; 
	posting-account=CYtergoAAAAOD8k-T_NdzknPJOBXmt8x
User-Agent: G2/1.0
X-HTTP-Via: 1.1 piinbcgw02
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) 
	Gecko/2009111605 Firefox/3.0.15ms1,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:604229

Let's say I have a long vector of 0-1 numbers:

0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0

Here 1's are our targets.

How to find the location of  the first kth element of 1 in the 1-
blocks?

And

How to find the location of  the last kth element of 1 in the 1-
blocks?

And

How to find the location of the median position of 1 in the 1-blocks?
(i.e. if there are 5 1's, then the median position should be the 3rd
1's location)

How to do this efficiently?

(not asking for something involving lots of for loops...)

Thanks