how to shift in timetable?

조회 수: 13 (최근 30일)
pooria mazaheri
pooria mazaheri 2018년 10월 31일
답변: dpb 2018년 10월 31일
i have this timetable how can i shift date time to the nearest date in timetable?
time_table = timetable({'1-Mar-2018 21:00' ; '6-Mar-2018 22:23'; '8-Mar-2018 18:20'}, ...
[1.13 ; 2.2 ; 3], {'a' , 'b' , 'c'});
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2018년 10월 31일
time_table = timetable(datetime({'1-Mar-2018 21:00' ; '6-Mar-2018 22:23';...
'8-Mar-2018 18:20'},'I','dd-MMM-uuuu HH:mm'),[1.13 ; 2.2 ; 3],...
{'a' ; 'b' ; 'c'})

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

답변 (1개)

dpb
dpb 2018년 10월 31일
First need to clean up the syntax for creating the time table -- as written one gets:
>> time_table=timetable({'1-Mar-2018 21:00' ; '6-Mar-2018 22:23'; '8-Mar-2018 18:20'}, ...
[1.13 ; 2.2 ; 3], {'a' , 'b' , 'c'});
Error using tabular/countVarInputs (line 267)
All variables must have the same number of rows.
Error in timetable (line 246)
[numVars,numRows] = tabular.countVarInputs(varargin);
>>
Oh; the last is a row cell array instead of column...change commas to semi-colons and try again...
>> time_table = timetable({'1-Mar-2018 21:00' ; '6-Mar-2018 22:23'; '8-Mar-2018 18:20'},[1.13 ; 2.2 ; 3], {'a' ; 'b' ; 'c'});
Error using timetable (line 291)
Provide datetime or duration vector for row times to create timetable.
>>
Well, that doesn't work yet, either...wrap the times in call to datetime and try again...
>> time_table = timetable(datetime({'1-Mar-2018 21:00'; '6-Mar-2018 22:23'; '8-Mar-2018 18:20'}),[1.13 ; 2.2 ; 3], {'a' ; 'b' ; 'c'});
>>
OK, now we are there...on to the question asked (I actually used tt for the variable for brevity, use your chosen name as desired)--
>> tt.Time=dateshift(tt.Time,'start','day')
tt =
3×2 timetable
Time Var1 Var2
____________________ ____ ____
01-Mar-2018 00:00:00 1.13 'a'
06-Mar-2018 00:00:00 2.2 'b'
08-Mar-2018 00:00:00 3 'c'
>>
It's unfortunate lack in the documentation that dateshift isn't linked to under timetable but only with information on dates and times variable types and that retime doesn't have an option to turn off the interpolation or aggregation.

카테고리

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