How to NaN data in a time series if it changes quickly?

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

Are you storing the time series as vectors?
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.
Hi Image Analyst. I do have the Image Processing toolbox. How would I use it to achieve this?
Your code also seems to be onthe right track, and I am currently trying to adapt it to my data. Thank you.

댓글을 달려면 로그인하십시오.

 채택된 답변

Cedric
Cedric 2013년 2월 18일
편집: Cedric 2013년 2월 19일
Or this (assuming that your data is stored in variable data):
lid = diff(data) <= -5 ;
data([lid, 0] | [0, lid]) = NaN ;

댓글 수: 1

This is great. I had to adjust it slightly to run on drops, an their associated rises. Thanks heaps Ben

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 2월 16일
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]);

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

질문:

2013년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by