consecutive combination of numbers from a list

1 view (last 30 days)
any quick methods to obtain a count of complete consecutive n numbers from a array list 1:m e.g. a list 1:21 and n=3 so
it would be 1:3,4:6,7:9,10:12,13:15,16:18,19:21,2:4,5:6,...17:19,3:5,...18:20= 19 combinations.

Accepted Answer

Bruno Luong
Bruno Luong on 15 Aug 2019
Edited: Bruno Luong on 15 Aug 2019
>> (1:19)'+(0:2) % (1:m-n+1)'+(0:n-1)
ans =
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12
11 12 13
12 13 14
13 14 15
14 15 16
15 16 17
16 17 18
17 18 19
18 19 20
19 20 21

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!