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

19 views (last 30 days)
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!

Accepted Answer

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

More Answers (1)

Wayne King
Wayne King on 2 Apr 2013
Edited: Wayne King on 2 Apr 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.

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!