MATLAB: Select every Nth row from number groups

findlogical?matrixmatrix manipulation

I have a vector that looks like
a = [1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1….]
I would like to find the vector location where I would find the first 1, second 1, third 1 and so on, in the trains of 1's in a quickish way.
As an output… I would like new vectors containing only the first 1 in every sequence of 1's
eg
b = [1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0....]
c = [0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0....]
OR
a Matrix containing the locations of each number in a sequence…
b = [1 13 19]
c = [2 14 20]
d = [3 15 21].... and so forth

Best Answer

I eventually solved this, and am posting my solution... The actual example had some strings containing a mixture of A and B's also, so that's included in this answer.
a='A'
b='B'
aab='AAB'
asandbs=[a;a;a;a;a;a;aab;b;b;b;b;b;b;b;b;a;a;a;a;a;b;b;b;b;a;a;a;a;a;a;a]
str2cell(asandbs)
Blocs=strcmp(asandbs,'B')==1;
Alocs=strcmp(asandbs,'A')==1;
changeovers=~(Alocs+Blocs);
Borders=zeros(size(Blocs,1),1);
for i=2:size(Blocs,1)
if Blocs(i,:)==1
Borders(i,1)=1+Borders(i-1,1)
else
Borders(i,1)=0
end
end
Then repeat the loop for A's