How to NaN data in a time series if it changes quickly?
Show older comments
Hi, I have a time series, where the data occasionally drops in value quickly due to artifacts. I would like a fucntion that moves along the data and if it detects a drop of 5 over two consecutive data points, it turns both of those data points into NaNs.
I'm quite limited in matlab experiance, so was wondering if anyone has any ideas how to approach this? Thanks Ben
3 Comments
Daniel Jaló
on 16 Feb 2013
Are you storing the time series as vectors?
Image Analyst
on 16 Feb 2013
Why over 2? Why keep it if the drop is only 1 element long? Also, do you have the Image Processing Toolbox, because this is easy if you do.
Ben Jaquiery
on 18 Feb 2013
Accepted Answer
More Answers (1)
Image Analyst
on 16 Feb 2013
Try this:
% Create sample data.
data = 1 : 30;
data(10) = 2; % drop only one element long.
data(20:21) = [14, 9] % 2 element long drop.
data(25:27) = [14, 9, 3] % 3 element long drop.
subplot(1,2,1);
plot(data, 'bd-');
grid on;
% Find differences
diffs = [0 diff(data)]
% Find drops of 5 or more.
bigDrops = num2str(diffs <= -5)
bigDrops(bigDrops==' ')=[] % Get rid of spaces.
% Get rid of single element drops.
bigDrops=strrep(bigDrops, '010', '000')
% Replace data with nans in those elements.
data(bigDrops == '1') = nan;
% Plot results.
subplot(1,2,2);
plot(data, 'bd-');
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!