how to delet multiple rows with single criteria in matlab
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 18 de Mzo. de 2015
Editada: Image Analyst
el 18 de Mzo. de 2015
Assuming your data is in cell array "data"
x = data{:, 2}; % Extract column 2.
rowsToDelete = x >= 3;
filteredData = data(~rowsToDelete, :);
James Tursa
el 18 de Mzo. de 2015
Editada: James Tursa
el 18 de Mzo. de 2015
Are you trying to delete all three H1, H2, H3 rows if any of the x values in those rows are >= 3? If so, in your example it looks like all the rows will be deleted since the first set has H3 x = 3 and the 2nd set has H3 x = 4. Is this correct? And is your data in a cell array? If so, here is one way:
c = your cell array;
xlimit = 3; % or whatever
x = repmat(any(reshape(cell2mat(c(:,2)),3,[])>=xlimit),3,1);
c(x(:),:) = [];
2 comentarios
alex solomon
el 18 de Mzo. de 2015
James Tursa
el 18 de Mzo. de 2015
So something like this?
c = your cell array;
xlimit = 3; % or whatever
x = repmat([c{2:3:end,2}]>=xlimit,3,1);
c(x(:),:) = [];
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!