I have the following vector of logicals:
vect1 = [0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1]
I would like to locate all the 1
value "clusters" within this vector along with their starting and ending indices. For output, I would like to be able to come up with something like:
5 8
13 15
18 19
23 23
where the first number is the "starting" index of each cluster and the second number is the "ending" index of each cluster.
EDIT: I was able to get this to work with a modified version of Shai's answer:
pv = [vect1 0];
sv = [0 pv(1:(end-1))];
ev = [pv(2:end) 0];
starting = find( pv - sv == 1 )
ending = find( pv - ev == 1 )