I'm having great difficulty coding the following in MATLAB: Suppose you have the following vector:
a
b
c
d
e
f
g
h
...
Specifying an (even) window size, create the following matrix of dimensions L
rows by n
columns (example, L = 4
):
a c e ...
b d f ...
c e g ...
d f h ...
Even more difficult is taking a vector of arbitrary length, specifying the number of windows, and optimizing (maximizing) the window size so less values at the end of the vector are dumped.
Create the matrix of indices into your vector. For L=4 (I assume you are overlapping by L/2), the indices are [1,2,3,4;3,4,5,6;5,6,7,8] etc. Let x = 1:L, y = L/2, the vector of indices is x+0y,x+1y,x+2y, and so on.
% let your initial data be in vector "data"
L = 4
N = floor(length(data)/(L/2))-1 % number of windows, or you specify this
mi = repmat(1:L,[N,1]) + repmat((L/2) * (0:(N-1))',[1,L]) % x + y * 0,1,2...
out = data(mi) % out is N-by-L, transpose to L-by-N if you like
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With