Creating the right indexes with bsxfunshould certainly help:
ind = bsxfun(@plus, 1:W, (0:X:numel(T)-W).');
out = T(ind);
Creating the right indexes is the first step indicated by the first line of code. What this code does is that it creates a 2D matrix, where each row is an element to access the window of interest. If you want to get an intuition about how code generates indexes, look specifically at the first case when X = 1;and W = 3;.
, 1, 2, 3. 2, 3, 4... , 5, 6, 7. , , 1, 2, 3 1 W. , T . 0, - 1 , 3. , 1 . 1 , 2 . , , , T.
, X = 2; W = 3;, , 1, 2, 3. 1, 2, 3 , 3, 4, 5 , 5, 6, 7 . 2 1 . 2 , 4 ..
1:W, 0:X:numel(T)-W. W , . , , bsxfun .
1:W, (0:X:numel(T)-W).', . , 0, X , , . , numel(T)-W, . bsxfun, 2D-, , , , , , , .
W = 3; X = 1; :
>> T = [1, 5, 6, 8, 10, 14, 22];
>> X = 1;
>> W = 3;
>> ind = bsxfun(@plus, 1:W, (0:X:numel(T)-W).')
ind =
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
, W = 3; X = 2;, :
>> T = [1, 5, 6, 8, 10, 14, 22];
>> X = 2;
>> W = 3;
>> ind = bsxfun(@plus, 1:W, (0:X:numel(T)-W).')
ind =
1 2 3
3 4 5
5 6 7
, T, .
, , :
out = T(ind);
X = 1; W = 3; :
>> out = T(ind)
out =
1 5 6
5 6 8
6 8 10
8 10 14
10 14 22
X = 2; W = 3; :
>> out = T(ind)
out =
1 5 6
6 8 10
10 14 22