MATLAB: Find order of increasing integers

integerssorting

I have a vector
[3,4,8,9,10,13]
How can I sort this into
[3,4]; [8,9,10]; [13];
in an efficient way? I.e., split the parts of the vector where there is a linear increase of +1 from the previous entry.

Best Answer

V = [3,4,8,9,10,13];
D = diff(find([true,diff(V)~=1,true]));
C = mat2cell(V,1,D)
C = 1×3 cell array
{[3 4]} {[8 9 10]} {[13]}