Начиная с вашего примера ...
v = [ 0 0 0 0 0 0 0 8 9 1 0 0 3 2 0 0 0 0 0 6 6 2 0 0 0 1 ];
Мы могли бы сделать следующее:
% 1. Create an index `idx` which groups elements either as zeros or non-zeros,
% with an increasing group number for each subsequent set
idx = cumsum( [1, diff(v==0) ~= 0] );
% = [ 1 1 1 1 1 1 1 2 2 2 3 3 4 4 5 5 5 5 5 6 6 6 7 7 7 8 ];
% 2. Split by this group, regardless of what's in it
grps = splitapply( @(x){x}, v, idx );
% = { {1×7 double}, {1×3 double}, {1×2 double}, {1×2 double}, {1×5 double}, ... }
% 3. Get the indices for groups, incremented when the 5-zeros condition is met
zIdx = cellfun( @(x) x(1) == 0, grps ); % Just alternating 0/1, as groups alternate
idx = cellfun( @numel, grps ) >= 5 & zIdx;
idx = cumsum( idx ) .* ~idx;
% = [ 0 1 1 1 0 2 2 2 ]
% 4. Group everything together
out = arrayfun( @(x) [grps{idx==x}], 1:max(idx), 'uni', 0 );
% { [8 9 1 0 0 3 2], [6 6 2 0 0 0 1] }
Я не уверен, что это быстрее, чем просто написать цикл .. .