MATLAB: Split binary array based on value 1

arraysplit

Hi,
I have a binary array that I would like to split up into several others, each starting with a '1'. I almost have it to work, except the sizes do not match and mat2cell does not work. Please help me with the last bit, thanks!
Jasper
a = [ 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]';
indices = find(a(:,1)~= 0); % gives 1,5,11,16 and is correct
sizes = diff([indices' size(a, 1)]);% gives 4,6,5,13 instead of 4,6,5,14!
mat2cell(a, sizes, size(a, 1)); % fail!

Best Answer

sizes = diff([indices' size(a, 1)+1])