Help correcting a messy time series data
显示 更早的评论
Hi,
I have multiple files of "daily" minimum temperature. The time series is non-continuos. Files start and end in different dates, some days in the middle are missing (the rows are missing), and some days have more than one measurement.
This is an example of what I have:
1999 01 01 5.2
1999 01 02 4.3
1999 01 02 5.0
1999 01 02 4.1
1999 01 03 3.8
1999 01 05 3.2
...
So day 02-jan has 3 different meassurements and day 04-jan is missing. Say that I need all the files to begin at 31-dec-1998 and end at 07-jan-1999, my files should end up looking like this:
1999 12 31 6.6
1999 01 01 5.2
1999 01 02 4.1
1999 01 03 3.8
1999 01 04 NaN
1999 01 05 3.2
1999 01 06 NaN
1999 01 07 NaN
I still need to:
1) take the minimum value of the days with more than one measurement. I have absolutely no idea how to do this...
2) complete the period with NaN or crop the data between the starting and the ending date that I need. So far I managed with a long and messy script to crop and/or add the missing data at the end. But I couldn't make that work for the beggining, and I'm sure there must be an easier, more effective way of doing so.
I would appreciate any help you can give me!
采纳的回答
更多回答(1 个)
Andrei Bobrov
2015-7-2
编辑:Andrei Bobrov
2015-7-3
d = [
1998 12 14 6
1999 01 01 5.2
1999 01 02 4.3
1999 01 02 5.0
1999 01 02 4.1
1999 01 03 3.8
1999 01 05 3.2
1999 02 12 8]
[y,m,dy] = datevec((datenum([1998 12 31]):datenum([1999 1 7]))');
daout = [y,m,dy];
[a,~,c] = unique(d(:,1:3),'rows');
d2 = accumarray(c,d(:,end),[],@min);
[lo,ii] = ismember(a,daout,'rows')
daout(:,end+1) = nan;
daout(ii(lo),end) = d2(lo);
类别
在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!