MATLAB: How to delete rows from a matrix when the interval is smaller than a certain value

loop

Hello,
My data consists of position(column 1) and signal(column 2) with hundreds of rows. Something like [5 90; 7 87; 12 85; 23 80; 39 72; 46 65; 58 61; 70 56; 75 50]
I want to make sure the interval between each position is larger than a certain value (15 in my case). The matrix should become [5 90; 23 80; 39 72; 58 61; 75 50]
I set i=1:length(matrix)-and the interval=position(i+1,1)-position(i,1), then execute the loop to delete row(i+1) when interval<15. However it only delete the first row(i+1) without check if position(i+2,1)-position(i,1)<15 or not. What condition should I put into to continuously delete all the following rows until every interval >15?

Best Answer

I would first select the rows to keep using a loop:
X = [5 90; 7 87; 12 85; 23 80; 39 72; 46 65; 58 61; 70 56; 75 50]
N = size(X,1) ;
KeepRow = false(N,1) ;
LastRow = 1 ;
KeepRow(LastRow) = true ; % keep the first
for k=2:N
if X(k,1) - X(LastRow,1) > 15
KeepRow(k) = true ; % this one is far enough
LastRow = k ; % make this the last row kept
end
end
Y = X(KeepRow,:)