I've a vector that I would like to split into overlapping subvectors of size cs in shifts of sh. Imagine the input vector is:
v=[1 2 3 4 5 6 7 8 9 10 11 12 13]; % A=[1:13]
given a chunksize of 4 (cs=4) and shift of 2 (sh=2), the result should look like:
[1 2 3 4]
[3 4 5 6]
[5 6 7 8]
[7 8 9 10]
[9 10 11 12]
note that the input vector is not necessarily divisible by the chunksize and therefore some subvectors are discarded. Is there any fast way to compute that, without the need of using e.g. a for loop?
In a related post I found how to do that but when considering non-overlapping subvectors.
What about this? First I generate the starting-indices based on
csandshfor slicing the single vectors out of the full-length vector, then I delete all indices for whichidx+cswould exceed the vector length and then I'm slicing out the single sub-vectors viaarrayfunand afterwards converting them into a matrix:E.g. for
cs=5; sh=3;this would give:Depending on where the values
cs; shcome from, you'd probably want to introduce a simple error-check so thatcs > 0;as well assh < cs.sh < 0would be possible theoretically if you'd want to leave some values out in between.EDIT: Fixed a very small bug, should be running for different combinations of sh and cs now.