MATLAB has many ways to do this by manipulating indexes, procedural approaches, vectorized solutions, etc. However, I cannot help but think about how simple some tasks can be if MATLAB had a little support for a functional programming style. In this spirit, I present the following solution. Make sure that you do not yet have values ββin these variables during the definition.
take=@ (mat,n)mat(1:n) partition=@ (mat,L)cell2mat(arrayfun(@(x)take(circshift(mat(:),-x*L/2),L),... 0:fix((length(mat)-L)/2+1)-1,'UniformOutput',0))
Now try using a test vector:
partition(1:10,4) %ans = % 1 3 5 7 % 2 4 6 8 % 3 5 7 9 % 4 6 8 10
The above solution discards the final values ββat the end of the vector that do not correspond to the length L after the section. Now you can expand it to process other devices and determine the optimal window lengths for minimal time loss, etc.
source share