Detecting missing data, tangent = 0, for given data.
2 views (last 30 days)
Hi! I have some data given in a file, where some data has gone missing. When plotting the data against time, this missing data appears as a flat plot (tangent = 0) against the respective time. For information, there are about 30 measurement per second. I am interessted in detecting when there is missing data for more than 2 seconds, and if you are feeling brave; displaying for which time or the elements of the missing data (for more than 2 seconds). If there are more than one place where there are missing data for more than 2 sec, they all should be given.
I have tried to approach this by both detecting if the data has not changed from the current index to the next, and when the tangent is about 0.
This is my code per now, but it is not done, nor any good.
Thank you in advance!
%%% With Tangent %%%
data = load('x.mat');
Y = tan(data.XPOS); %This is the x-positions from the file
crit = find(Y<=0.000001);
arr = ;
while crit(i)==crit(i+1) %checks if the tangent for the following element is also 0
counter = counter+1;
if counter > 60 %about 2 seconds
arr = crit() %want to add all the elements which the tangent is 0 (for 2 seconds), don't know how
counter = 0; %if the tangent is 0 for less than 2 sec, reset the counter
Sergey Kasyanov on 21 Jun 2021
The approach is very simple: get array with 1 when Y = 0 and 0 otherwise, then detect when 0 changes to 1 and 1 changes to 0 (by diff), then reshape array with position of changing to convinient form and get difference between position in pairs. If diffrerence is greater than 60, then save it in c and print the message.
c = reshape(find(diff([nan, Y, nan] <= 0.000001)), 2, );
c(1, :) = c(1, :) + 1;
c = c(:, diff(c) > 60);
for i = 1:size(c, 2)
fprintf('Times from %i to %i is missed\n', c(1,i), c(2,i));