MATLAB: How to create a cell that splits a sequence of numbers (1 : n) in equal parts

cell arraysMATLAB

If I have a sequnce of numbers (1 : 40) I want to create a cell which splits that sequence into ({1 : 20} {21 : 40}) or of I want to go a step further ({1 : 10}{11 : 20}{21 : 30}{31 : 40}) and so on.

Best Answer

Using mat2tiles,
>> C=mat2tiles(1:40,[1,10]);
>> C{:}
ans =
1 2 3 4 5 6 7 8 9 10
ans =
11 12 13 14 15 16 17 18 19 20
ans =
21 22 23 24 25 26 27 28 29 30
ans =
31 32 33 34 35 36 37 38 39 40