Note that I'm using Matlab R2013b. So, I have a toy input matrix of 10x2 size:
inputM = [NaN 4 7 NaN 9 NaN NaN NaN NaN NaN; NaN NaN 8 10 2 NaN 3 NaN NaN NaN]
I have the lowest and highest positions where the non-NaN values are located in each column:
lowest_idx = [2 3]
highest_idx = [5 7]
I want to shift the bulk rows, between the lowest and highest positions, downward according to a shifting index shift_idx = [3 2]
. The output matrix I need to obtain looks like
outputM = [NaN NaN NaN NaN 4 7 NaN 9 NaN NaN; NaN NaN NaN NaN 8 10 2 NaN 3 NaN]
I can do this using a for loop
like this:
for i = 1:length(shift_idx)
inputM(lowest_idx(i)+shift_idx(i):highest_idx(i)+shift_idx)(i),i) = inputM(lowest_idx(i):highest_idx(i),i);
inputM(1:lowest_idx(i)+1,i) = nan;
end
However, my real matrix has over 1 million columns, so I'd like a more efficient solution. Anyone has an idea of how to do this without a for loop
?