How to delete rows where one element is forced to meet some criteria off of a 2xn array

15 次查看(过去 30 天)
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!

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-4-2
A = [time column, measurement column]
B = A(A(:,2)>threshold,:)

更多回答(1 个)

Wayne King
Wayne King 2013-4-2
编辑:Wayne King 2013-4-2
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.

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by