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 件のコメント
採用された回答
Azzi Abdelmalek
2013 年 4 月 2 日
A = [time column, measurement column]
B = A(A(:,2)>threshold,:)
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!