How do I select n elements of a sequence in windows of m ? (matlab)

前端 未结 5 1159
温柔的废话
温柔的废话 2021-01-19 10:47

Quick MATLAB question. What would be the best/most efficient way to select a certain number of elements, \'n\' in windows of \'m\'. In other words, I want to select the fir

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-19 11:10

    Do you have enough RAM to store a 50-by-nWindow array in memory? In that case, you can generate your windows in one go, and then apply your processing on each column

    %# idxMatrix has 1:50 in first col, 11:60 in second col etc
    idxMatrix = bsxfun(@plus,(1:50)',0:10:length(yourVector)-50); %'#
    
    %# reshapedData is a 50-by-numberOfWindows array
    reshapedData = yourVector(idxMatrix);
    
    %# now you can do processing on each column, e.g.
    maximumOfEachWindow = max(reshapedData,[],1);
    

提交回复
热议问题