整流化されたデータから任意の閾値以下かつ100以上連続するデータの抽出方法を知りたいです
조회 수: 18 (최근 30일)
이전 댓글 표시
イメージはこの図におけるT1です。このT1はThreshold以下で連続する100個以上のデータです。特に”連続する100個以上のデータ”の部分について詳しく知りたいです。댓글 수: 0
답변 (1개)
Hernia Baby
2022년 5월 2일
まずはサンプルを作ります
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
Hernia Baby
2022년 7월 15일
편집: Hernia Baby
2022년 7월 15일
最後の点を認識しないようにしているからです
データ量は増えますが、以下のようにするとうまくいくと思います
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



