How to find end of time series in plot
조회 수: 13 (최근 30일)
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');
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;
index = ;
%len = ;
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
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;
counter = 0;
%%%%%% Plot critical points %%%%%%
start(k)= index(k)- 28*20;
endd(k) =index(k) + 28*70; % +28*70 is buffer after the first index of missing data
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
for ind = 1:numel(stalepos)-1
disp(pos(stalepos(ind):stalepos(ind+1)-1)) %display the values between the sequences.
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.