OK. Provided that the zeros appear periodically just the way you have shown in your code, you could use
indz = find(A==0);
numr = indz(2)-indz(1)-1;
A(A == 0) = [];
B = reshape(A,numr,length(A)/numr)
Again, if there is not a constant number of non-zero elements in each interval (that includes also the last interval) you end up with different row lengths. In that case you cannot build a matrix that satisfies your requirements.
Best Answer