필터 지우기
필터 지우기

How do I use movsum with a timetable?

조회 수: 3 (최근 30일)
SaaraL
SaaraL 2021년 2월 22일
댓글: Walter Roberson 2021년 2월 23일
I have a 79880x42 timetable:
Date Station1 Station2 Station3
01-Jan-2011 00:00:00 0 0 0
01-Jan-2011 01:00:00 0.3 0 0
01-Jan-2011 02:00:00 0.4 0 0.6
I want to use movsum function to get the moving sum of 2 hours, 3 hours...12 hours of each station.
So far I have tried M2h = movsum(tt,k,'SamplePoints',Date), where tt=timetable, k=duration (2 hours), Date=datetime vector. But trying different variations of this function only gives me different errors such as "Invalid data type. First input must be numeric or logical." or "Unrecognized function or variable 'Date'.".

답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 22일
Date = datetime('now') - (days(30):days(-1):days(0)).';
Station1 = sort(rand(31,1));
tt = timetable(Date, Station1)
tt = 31x1 timetable
Date Station1 ____________________ _________ 23-Jan-2021 22:08:38 0.0039546 24-Jan-2021 22:08:38 0.050015 25-Jan-2021 22:08:38 0.10765 26-Jan-2021 22:08:38 0.17637 27-Jan-2021 22:08:38 0.19403 28-Jan-2021 22:08:38 0.25825 29-Jan-2021 22:08:38 0.27809 30-Jan-2021 22:08:38 0.27946 31-Jan-2021 22:08:38 0.31052 01-Feb-2021 22:08:38 0.31613 02-Feb-2021 22:08:38 0.34986 03-Feb-2021 22:08:38 0.41445 04-Feb-2021 22:08:38 0.41544 05-Feb-2021 22:08:38 0.4175 06-Feb-2021 22:08:38 0.50128 07-Feb-2021 22:08:38 0.53827
k = hours(randi(7))
k = duration
5 hr
M2h = movsum(tt.Station1, k, 'SamplePoints', tt.Date)
M2h = 31×1
0.0040 0.0500 0.1076 0.1764 0.1940 0.2582 0.2781 0.2795 0.3105 0.3161
  댓글 수: 2
SaaraL
SaaraL 2021년 2월 23일
Thank you for your answer, but it still didn't work for me.
I get two error messages:
  1. Error using convertMovfunArgs (line 19)
'SamplePoints' value contains Inf or NaT.
2. Error in datetime/movsum (line 104)
args = convertMovfunArgs(varargin{:});
Walter Roberson
Walter Roberson 2021년 2월 23일
find(isnat(tt.Date))

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by