MATLAB: How to delet multiple rows with single criteria in matlab

remove rows

I have 900 by 4 mixed data. The first column contains letter of atom and the rest column is the XYZ coordinates of the atom. The arrangement of the atom looks like H1;H2;H3………. this three rows repeat it self until the number of rows are 900.
x y Z
H1 1 2 3
*H2 2 4 7*
H3 3 0 0
H1 1 1 1
*H2 0 0 0*
H3 4 6 7
.
.
.
.
So how can i remove those three rows ( H1;H2;H3) if x of H2 >=3 else keep it.the data is a cell array.The main point is i only take as a criteria the value of x corresponds to H2. From 900 rows 300 of them are H2.For instance If the first H2(second row) satisfy the criteria i want to delet H1;H2;H3 and got the next H2.If it doesn't satisfy the criteria i will keep the three rows and go to the next H2.

Best Answer

Step 1: reshape the cell array so each row is H1 x y z H2 x y z H3 x y z:
new_c = reshape(c', 12, [])';
Step 2: find out which of the row of the reshaped cell array has x of H2 (column 6) above your threshold
rowstodelete = cell2mat(new_c(:, 6)) > 3;
Step 3: delete these rows:
new_c(rowstodelete, :) = [];
Step 4: reshape back to original n*4 columns
new_c = reshape(new_c', 4, [])'