How to delete rows where one element is forced to meet some criteria off of a 2xn array
조회 수: 9 (최근 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!
댓글 수: 0
채택된 답변
추가 답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!