Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 first 50 elements of a sequence, then elements 10-60, then elements 20-70 ect. Right now, my sequence is in vector format(but this can easily be changed).

EDIT: The sequences that I am dealing with are too long to be stored in my RAM. I need to be able to create the windows, and then call upon the window that I want to analyze/preform another command on.

like image 667
thepro22 Avatar asked Feb 24 '23 06:02

thepro22


1 Answers

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);
like image 63
Jonas Avatar answered May 16 '23 08:05

Jonas