同じ条件を10行満たした最初の値を抽出する
Afficher commentaires plus anciens
添付したCSVファイルの内から30以下になる値が連続で20回続く最初の値の位置を特定したいです。
似たような質問がありましたが、応用できず質問しました。
よろしくお願いします。
Réponse acceptée
Plus de réponses (1)
Hernia Baby
le 15 Déc 2022
Modifié(e) : Hernia Baby
le 15 Déc 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 commentaire
Catégories
En savoir plus sur 構造化データと XML ドキュメント dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!