整流化されたデータから任意の閾値以下かつ100以上連続するデータの抽出方法を知りたいです
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
イメージはこの図におけるT1です。このT1はThreshold以下で連続する100個以上のデータです。特に”連続する100個以上のデータ”の部分について詳しく知りたいです。
0 commentaires
Réponses (1)
Hernia Baby
le 2 Mai 2022
まずはサンプルを作ります
t = 0:1/1e3:8;
x = sin(t+5).^3+cos(2*pi*(t+5))+3;
threshold = 3.95;
n = 200;
一度図示していきましょう
figure
hold on
plot(t,x,'Color',[.4 .4 .4])
yline(threshold,'--r')
hold off
今回は、上図の閾値以上でn=200より連続点が大きい部分を抜き出します
こちら を参考にして正負ともにカウントしていきます
そのあと差分をとり、カウントがリセットされるまでの場所を探します
idx = x >= threshold;
cells = cell2mat(arrayfun(@(t)1:t,diff(find([1 diff(idx) 1])),'un',0)).*idx;
idx1 = find([diff(cells) 0] < 0)
ここで n = 200点より多い配列を抽出します
idx1 = idx1(cells(idx1) > n);
num = cells(idx1)
for ii = 1:length(idx1)
start = idx1(ii)-num(ii)+1;
fin = idx1(ii);
T{ii} = t(start:fin);
X{ii} = x(start:fin);
end
さて後はXを見ればいいのですがせっかくなので、図示してみましょう
figure
hold on
plot(t,x,'Color',[.4 .4 .4])
yline(threshold,'--r')
cellfun(@(t,x) plot(t,x), T,X)
hold off
2 commentaires
Hernia Baby
le 15 Juil 2022
Modifié(e) : Hernia Baby
le 15 Juil 2022
最後の点を認識しないようにしているからです
データ量は増えますが、以下のようにするとうまくいくと思います
clear,clc,close all;
t = 0:1/1e3:8;
x = sin(t+5).^3+cos(2*pi*(t+5))+3;
threshold = 3;
n = 200;
figure
hold on
plot(t,x,'Color',[.4 .4 .4])
yline(threshold,'--r')
hold off
以下の部分を書き換えました
idx = x > threshold;
cells = cell2mat(arrayfun(@(t)1:t,diff(find([1 diff(idx) 1])),'un',0)).*idx;
idx1 = find([diff(cells) 0] <= 0); %ここ
後は同じです
idx1 = idx1(cells(idx1) > n);
num = cells(idx1)
for ii = 1:length(idx1)
start = idx1(ii)-num(ii)+1;
fin = idx1(ii);
T{ii} = t(start:fin);
X{ii} = x(start:fin);
end
figure
hold on
plot(t,x,'Color',[.4 .4 .4])
yline(threshold,'--r')
cellfun(@(t,x) plot(t,x), T,X)
hold off
Voir également
Catégories
En savoir plus sur Grid Lines, Tick Values, and Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!