MATLAB: SUBSTRINGS CREATION WITH DIFFERENT ORDER

MATLABstring

I wish to estimate substrings of length 4-13, a primary secuence currently about 150,000 binary numbers. How to create the substrings be as follows:
let's assume we have the following sequence (numbers in parentheses indicate the order):
s = 0 (1) 1 (2) 1 (3) 0 (4) 1 (5) 1 (6) 0 (7) 1 (8) 0 (9) 0 (10) 0 (11) 1 (12)
substrings of length 4 would be:
0 (1) 1 (2) 1 (3) 0 (4)
1 (2) 1 (3) 0 (4) 1 (5)
1 (3) 0 (4) 1 (5) 1 (6)
0 (4) 1 (5) 1 (6) 0 (7)
1 (5) 1 (6) 0 (7) 1 (8)
1 (6) 0 (7) 1 (8) 0 (9)
0 (7) 1 (8) 0 (9) 0 (10)
1 (8) 0 (9) 0 (10) 0 (11)
0 (9) 0 (10) 0 (11) 1 (12) .
Now would do the same with the substrings of length 5 After substrings of length 6 ….. up length 13
Many thanks

Best Answer

s =[ 0 1 1 0 1 1 0 1 0 0 0 1 ];
n=6;
m=numel(s)-n+1;
A=zeros(m,n);
idx=cell2mat(arrayfun(@(x) x:x+n-1,(1:m)','un',0));
out=s(idx)