Moving sum in a timetable
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I've timetable with 2 clomuns (time column) 527040×1 datetime and 527040×1 double (1st column) , please look at my attached screenshot :)
the datetime is on a minutley basis from 01.01.2018 00:00:00 until 01.01.2019 23:59:00
I want to calculte the moving sum or sum of the double column for t0 = sum over the next 5 minutes startting at t1
So it should be value at t0 = sum of of double from t1+...+t6
for value at t1 = sum t2+...+t7
and so on.....
any ideas :)
0 个评论
采纳的回答
Bob Thompson
2019-4-9
编辑:Bob Thompson
2019-4-9
I'm a little bit confused what you're asking for, but here is a first attempt. As I understand you are looking for each row to have a sum of the next several doubles. That would be done something like:
for i = 1:size(data,1) % I don't know what your data variable is called, replace as needed
if i+5<=size(data,1)
data(i,3) = sum(data(i+1:i+5,2));
elseif i+1<=size(data,1)
data(i,3) = sum(data(i+1:end,2));
else
data(i,3) = NaN;
end
end
I do not, off the top of my head, know a way to calculate a moving some without a loop in Matlab.
5 个评论
Steven Lord
2019-4-10
The limitation of this ability, however, is that the range values must be positive integers, so it is not possible to examine values exclusively in front of the summation index, as including 0 as the kb term will begin the summation at the current index.
If you specify datetime or duration as the value for the SamplePoints name-value pair argument, the window length values may be nonnegative integer values or may be duration values. So for this scenario using the timetable RowTimes as the SamplePoints in movsum would allow you to specify minutes([5 0]) as the window length input.
You are correct that you can't take the moving sum (or use any of the moving functions) and exclude the element around which the window is located. But for purposes of movsum that just leaves one post-movsum step. Use fillmissing or isnan to replace any NaN values in A with 0 if necessary then subtract A from the results of movsum. That should be fairly safe for most data sets.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!