Reducing nonuniform-timed data to x-minute averages
3 次查看(过去 30 天)
显示 更早的评论
I have an incredible amount of data recorded at nonuniform time intervals. I'll like to boil the data down to a multi-minute averages, which can be defined by a variable within the code, say "windowAvg" or "interval". I also have large gaps within the data where no data was recorded, and I'd need to represent that data as well with zeroes or "NaN" or something similar. Here's an example of what the data may look like:
- DATE TIME (HH:MM:SS) DATA
- 1-Mar-12 21:40:58 7.714284452
- 1-Mar-12 21:40:59 7.076270192
- 1-Mar-12 21:41:00 6.852246256
- 1-Mar-12 21:41:01 8.065426585
- 1-Mar-12 21:41:11 6.17580769
- 1-Mar-12 21:41:12 8.216123385
- 1-Mar-12 21:41:14 7.811008001
- 1-Mar-12 21:41:15 6.888230101....etc
And then what I need it to look like (for example, 5-min avg):
- DATE TIME (HH:MM:SS) DATA
- 1-Mar-12 21:40:00 7.825590127
- 1-Mar-12 21:45:00 7.488390079
- 1-Mar-12 21:50:00 NaN
- 1-Mar-12 21:55:00 7.314028628
My general plan was to create a full day's worth of a timestamp variable (I already have it in MATLAB serial time form), and then "find" where the data fall into the different time intervals, average, and then map the averaged value to the appropriate interval. I have a feeling, though, that there's an easier way to do this with obscure functions that I don't know about. I would appreciate any help.
Thanks, Nic
0 个评论
采纳的回答
Walter Roberson
2012-6-14
Use the two-output version of histc() on the serial date numbers in order to find out which interval each time is in. Feed the bin numbers and the actual data into accumarray(), specifying @mean as the function it should use, and specifying whichever fill value you want (default is 0). When you get the accumarray() result, use the row index to look up the serial date number of the bin (the one you handed to histc).
The code is quite straight forward once you understand histc() and accumarray()
5 个评论
Walter Roberson
2012-6-26
What that sounds like to me is roundoff error. 1/(24*60*60) is not representable as a finite binary number, so there could be round-off depending on how exactly the values were generated.
You could experiment to see if you get more accuracy by using datevec() on the string times, as that breaks out the minutes field individually.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!