필터 지우기
필터 지우기

How to fill data gaps in a time series with NaN

조회 수: 2 (최근 30일)
Smith J
Smith J 2014년 10월 25일
댓글: Smith J 2014년 10월 27일
Dear All,
I am having a time series with some gaps in it and i want to fill the gaps with NaN, how can I do that the.....the interval of my time series is 0.00274
  댓글 수: 2
dpb
dpb 2014년 10월 26일
Are there missing entries or is there some other value present now?
Smith J
Smith J 2014년 10월 27일
I am having the time series....so how to do...I dont need to create any time series

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

채택된 답변

Star Strider
Star Strider 2014년 10월 26일
I am not certain what you want to do, but if you want to create a continuous time vector and fill the corresponding missing data values with NaN, this works:
Ts = 0.00274; % Sampling Time
t = [0:10 14:20 25:30]*0.00274; % Create Time Series With Gaps
f = rand(size(t)); % Create Matching Data
tn = round(t/Ts); % Create Indices With Gaps
dt = diff([0 tn]); % Create Vector Of Differences
tg = find(dt > 1); % Find Indices Of Gaps
gaps = dt(tg)-1; % Find Lengths Of Gaps
ti = linspace(min(t),max(t),max(tn)); % Create Continuous Time Vector
fi = interp1(t,f,ti); % Create Matching Data Vector
for k1 = 1:length(tg) % Loop Filling Gaps In ‘f’ With NaN
q = [tg(k1):tg(k1)+gaps(k1)-1];
fi(tg(k1):tg(k1)+gaps(k1)-2) = nan(1,gaps(k1)-1);
end
If you also want the time vector to have NaN values (not recommended), add this line after the ‘fi’ assignment in the loop:
ti(tg(k1):tg(k1)+gaps(k1)-1) = nan(1,gaps(k1));
The output of this routine are the time vector ‘ti’ and the data vector ‘fi’.
There are likely different ways to do this. This method seems to do what you want.
  댓글 수: 2
dpb
dpb 2014년 10월 26일
"There are likely different ways to do this"
Aren't there (almost) always? :)
One may be John d' Errico's inpaint_nans File Exchange submittal...
It gets (like all of John's most excellent submissions) rave reviews altho I don't know it'll solve OPs query directly as haven't actually used it meself...
Star Strider
Star Strider 2014년 10월 26일
Nor have I.
I usually just write my own code to solve specific problems, since it’s usually easier than learning someone else’s code and adapting it to my application.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by