Here is a solution, but there are many ways to do it, some simpler than others:
grouped = mat2cell( A, 1, diff( [0, find(diff(A) ~= 1), length(A)] )) ;
where grouped is a cell array with the following content
>> grouped{1}
ans =
1 2
>> grouped{2}
ans =
5 6 7 8 9
>> grouped{3}
ans =
20 21 22 23
Edit : here is a funny way for Star Strider, who wanted a tutorial about ACCUMARRAY ;-)
grouped = accumarray( cumsum([1, diff(A) ~= 1]).', A, [], @(x){x} ) ;
Best Answer