How to find end of time series in plot

7 ビュー (過去 30 日間)
Vilde Solberg
Vilde Solberg 2021 年 6 月 23 日
回答済み: Joseph Cheng 2021 年 6 月 23 日
Hi!
This is kind of a basic question.
I have a file containing a number of keys/positions (x-pos, y-pox, etc..) that again contains data within arrays. There are some missing data in this file, and the missing data appears as a flat line in the plot. I only care for the missing data that last for more that 2 sec (2*mps). I have managed to find the index of the beginning of the missing data, I don't know how to find the end (or technically the whole missing data interval). The reason I want to find the end as well is that I want to plot figures that shows the interval of the missing data, and some time-buffer at both ends so I can see how the plot behaves right before the data goes missing, and right after. Is there some way to find the end of each interval (or the end of them)?
Thank you in advance!
My code so far:
data = load('x.mat');
figure(1)
plot(data.Time,data.PITCH); %The whole graph
N = length(data.XPOS);
mps = length(data.Time)/(data.Time(end)); %measurements per second (about 28 meas/sec)
M = [];
arr = [];
counter = 0;
nc = 0;
nnc=0;
intervall=[];
index = [];
%len = [];
for i=1:length(data.XPOS)-1
if data.XPOS(i) == data.XPOS(i+1) %if the data repeats itself
counter = counter+1;
if counter > mps*2 % if tangent is repeated for more than 2 sec
nc = nc+1;
arr(nc) = data.XPOS(i);
%%%% trying to find end of interval here
if not(ismember(data.XPOS(i),M))
nnc=nnc+1;
M(nnc) = data.XPOS(i); % the x-pos that have missing data for more than 2 sec
intervall(nnc) = data.Time(i); % time of the critically missed data
index(nnc) = i;
end
end
else
counter = 0;
end
end
%%%%%% Plot critical points %%%%%%
start=[];
endd =[];
for k=1:length(M)
start(k)= index(k)- 28*20;
endd(k) =index(k) + 28*70; % +28*70 is buffer after the first index of missing data
figure(k+1)
plot(data.Time(start(k):endd(k)),data.XPOS(start(k):endd(k)));
end
  4 件のコメント
KSSV
KSSV 2021 年 6 月 23 日
Attach your data.
Vilde Solberg
Vilde Solberg 2021 年 6 月 23 日
I can't do that, I'm sorry. But replacing data.XPOS with a general array as: pos = [0.11, 0.12, 0.12, 0.12, 0.12 0.12, 0.14, 0.14, 0.11, 0.16, 0.13, 0.13, 0.13, 0.13] and counter > 3, it should work the same. The general code:
M = [];
arr = [];
counter = 0;
nc = 0;
nnc=0;
interval=[];
index = [];
len = [];
pos = [0.11, 0.12, 0.12, 0.12, 0.12 0.12, 0.14, 0.14, 0.11, 0.16, 0.13, 0.13, 0.13, 0.13];
for i=1:length(pos)-1
if pos(i) == pos(i+1)
counter = counter+1;
if counter > 3 % if tangent is repeated for more than 2 sec
nc = nc+1;
arr(nc) = pos(i);
%%%% trying to find end of interval here
if not(ismember(pos(i),M))
nnc=nnc+1;
M(nnc) = pos(i); % the x-pos that have missing data for more than 2 sec
interval(nnc) = pos(i); % time of the critically missed data
index(nnc) = i;
end
end
else
counter = 0;
end
end

サインインしてコメントする。

回答 (1 件)

Joseph Cheng
Joseph Cheng 2021 年 6 月 23 日
to go with your example of pos where
pos = [0.11, 0.12, 0.12, 0.12, 0.12 0.12, 0.14, 0.14, 0.11, 0.16, 0.13, 0.13, 0.13, 0.13];
you can find sequences of consecutive numbers by doing something like this
dpos = diff(pos); %diff from next
stalepos = [find(dpos~=0)+1 numel(pos)+1]%find edges of consecutive index where the difference is 0
stalepos = 1×6
2 7 9 10 11 15
for ind = 1:numel(stalepos)-1
disp(pos(stalepos(ind):stalepos(ind+1)-1)) %display the values between the sequences.
end
0.1200 0.1200 0.1200 0.1200 0.1200 0.1400 0.1400 0.1100 0.1600 0.1300 0.1300 0.1300 0.1300
now that last for loop we can see which ones have length > your minimum not missing/stale data threshold you can do whatever you need to.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by