how to shift in timetable?

6 ビュー (過去 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 Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by