Create matrix by repeatedly overlapping a vector

前端 未结 4 2044
再見小時候
再見小時候 2021-01-19 20:52

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 (e

4条回答
  •  悲哀的现实
    2021-01-19 21:13

    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
    

提交回复
热议问题