A = [1 2 9 10 11 12 13 17 18 20 21 23 24];
c1 = 1;
arrset = cell(0,0);
while(c1
while (c1+c2+1 c2 = c2+1;
end
if(c2>=1)
arrset= [arrset;(A(c1:1:c1+c2))];
end
c1 = c1 + c2 +1;
end
fprintf('有%d组连续数:\n',numel(arrset))
celldisp(arrset) % 显示这些连续数
效果:
arrset{1} =
1 2
arrset{2} =
9 10 11 12 13
arrset{3} =
17 18
arrset{4} =
20 21
arrset{5} =
23 24