MATLAB: Accelerate filter loop

filter

Hi everybody, I need to filter large data sets of about a million lines and some 15 columns. The data are echosounder readings, one data line per second. The simple thing I have to do is to remove those lines that exceed 3 m depth from one line to the next as these jumps are not plausible (they might be caused by fishes or air bubbles under the ship). I reduced my code to only find out the 'good' line numbers for later processing (instead of filtering the whole data set). Although this is quite simple, it takes ages and the speed seems to decrease being quick for the first 200 k lines but hen significantly slowing down. Does anybody know a quicker method to do such filtering? This is the code I use:
j=0;
for i=2:length(depthAlpha)
if abs(depthAlpha(i-1)-depthAlpha(i))<3
j=j+1;
goodlines(j,1)=i;
end
end

Best Answer

goodlines = find(abs(diff(depthAlpha(:)))<3)