Deleting rows with an if Statement
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Gaggini
el 19 de Mayo de 2022
Comentada: Voss
el 19 de Mayo de 2022
I am trying to delete any rows that agree with the statement Componentry_Analysis(:,6) == 1 and Componentry_Analysis(:,7) < 5, but I am unsure how to write an if statement with two statements and how to delete the rows if they agree with the statement.
My code so far:
[num_rows, num_cols] = size(Componentry_New_Mean);
for i=1:num_cols - 1
SD_Sort = Componentry_New_Mean(1:end,i) < 2;
Max_Sort= Componentry_New_Mean(1:end,i+1) < 6
Componentry_Analysis = [Componentry_New_Mean, SD_Sort, Max_Sort];
if Componentry_Analysis(:,6) == 1 and Componentry_Analysis(:,7) < 5
%delete rows
end
end
If anyone has any ideas that would be great?
0 comentarios
Respuesta aceptada
Voss
el 19 de Mayo de 2022
Here's a way to delete rows of a matrix if two conditions are both met:
x = magic(7)
% delete rows of x where the value in column 6 is > 30
% and the value in column 7 is < 40:
x(x(:,6) > 30 & x(:,7) < 40,:) = []
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!