同じ条件を10行満たした最初の値を抽出する
Show older comments
添付したCSVファイルの内から30以下になる値が連続で20回続く最初の値の位置を特定したいです。
似たような質問がありましたが、応用できず質問しました。
よろしくお願いします。
Accepted Answer
More Answers (1)
Hernia Baby
on 15 Dec 2022
Edited: Hernia Baby
on 15 Dec 2022
T = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1231787/test_data.csv');
30以下の数字かつ20行以上続く場合、最初の行番号を抜き出すようにします。
num = myFind(T,30,20,1)
そのときの数字がいくつかは以下のようにすればよいです。
T(num)
ーーーーーーーーー
関数はこちら
function num = myFind(T,threshold,n,m)
% threshold:閾値
% n:何行続くか
% m:何行目の番号を取得するか
x = T <= threshold;
a = cell2mat(arrayfun(@(t)1:t,diff(find([1 diff(x(:,1)') 1])),'un',0))';
num = find(a==n) - (n-m);
num = num(x(num));
end
1 Comment
Categories
Find more on 構造化データと XML ドキュメント in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!