필터 지우기
필터 지우기

Moving sum in a timetable

조회 수: 8 (최근 30일)
Antonio Melieni
Antonio Melieni 2019년 4월 9일
댓글: Steven Lord 2019년 4월 10일
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 :)

채택된 답변

Bob Thompson
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
Antonio Melieni
Antonio Melieni 2019년 4월 10일
Thanks Bob :)
Steven Lord
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by