A = [0 1 0 2 3 0] ;
ii = zeros(size(A));
jj = A > 0;
ii(strfind([0,jj(:)'],[0 1])) = 1;
idx = cumsum(ii).*jj;
iwant = accumarray( idx(jj)',A(jj)',[],@(x){x'})
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!