How to delete rows where one element is forced to meet some criteria off of a 2xn array
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey all. I did a good deal of searching, but I'm having some trouble removing specified elements of an array. Basically, I have a 'time' coordinate as one column, and a measurement as the other. I was hoping to find all those measurement values greater than some threshold, and keep them (ie toss those that don't meet that).
Two things I've tried:
A = [time column, measurement column]
B = A(A(:,2)>threshold)
But this only returns the threshold values.
for n =1:size(A(1)),
if A(n,2) < threshold,
A(n,2) = []
end
end
Attempting to delete the part of the array that is below threshold. Thanks for any input!
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 2 de Abr. de 2013
A = [time column, measurement column]
B = A(A(:,2)>threshold,:)
0 comentarios
Más respuestas (1)
Wayne King
el 2 de Abr. de 2013
Editada: Wayne King
el 2 de Abr. de 2013
I'll make up some data and show you (there are many ways to do this)
A = ones(20,2);
A(:,2) = randi([0 10],20,1);
A(:,1) = 1:20;
Threshold is 5
idx = find(A(:,2)>5);
B = A(idx,:);
Or
C = A(A(:,2)>5,:);
Of course, your time column is now not going to be evenly spaced.
0 comentarios
Ver también
Categorías
Más información sobre Operators and Elementary Operations 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!