Detecting missing data, tangent = 0, for given data.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 = [];
for i=0:length(crit)
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
for j=0:length(counter)
arr = crit() %want to add all the elements which the tangent is 0 (for 2 seconds), don't know how
end
else
counter = 0; %if the tangent is 0 for less than 2 sec, reset the counter
end
end
end
0 Kommentare
Antworten (1)
Sergey Kasyanov
am 21 Jun. 2021
Hello!
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));
end
7 Kommentare
Sergey Kasyanov
am 22 Jun. 2021
Bearbeitet: Sergey Kasyanov
am 22 Jun. 2021
If there are Y < 0 try that first line:
c = reshape(find(diff([nan, abs(Y), nan] <= 1e-6)), 2, []);
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!