MATLAB: How to delete rows in a matrix where two numbers exist side-by-side

delete rows

I have a large matrix that has thousands of rows.
I need to delete the rows based on the following condition:
>>> if in a row, ith column is 2 and (i+1)th column is 3
e.g. Input matrix [1, 2, 1; 1, 2, 1; 2, 2, 3]
Expected output: [1,2,1;1,2,1]

Best Answer

This should do the job. If you have a huge matrix and you want it to go faster, you will need to adapt this code to build up a vector with all rows that need deleting and do that once only (at the end).
A=[2,7,3;1, 2, 1; 1, 2, 1; 2, 2, 3; 1, 2, 1; 2, 3, 4]
rows=1;
while rows<=length(A)
if strfind(A(rows,:),[2 3])
A(rows,:)=[];
end
rows=rows+1;
end
A
Output:
A =
2 7 3
1 2 1
1 2 1
2 2 3
1 2 1
2 3 4
A =
2 7 3
1 2 1
1 2 1
1 2 1