how to shift in timetable?
6 次查看(过去 30 天)
显示 更早的评论
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
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!