how to shift in timetable?

6 visualizaciones (últimos 30 días)
pooria mazaheri
pooria mazaheri el 31 de Oct. de 2018
Respondida: dpb el 31 de Oct. de 2018
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 comentario
Andrei Bobrov
Andrei Bobrov el 31 de Oct. de 2018
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'})

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 31 de Oct. de 2018
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.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by