Error using time date table
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a table with time date hour values as:

I am trying to find the difference between the consecutive time and put in the same table as a new column. I want to keep column name as 'time diff'. I am trying this. Got this error.
time= table2array(Data(:,1));
diff=diff(time);
Data=outerjoin(Data,diff,'MergeKeys',true);
error:
Function 'subsindex' is not defined for values of class 'datetime'.
Any suggestions?
0 comentarios
Respuestas (1)
Peter Perkins
el 11 de Mzo. de 2019
>> tt = timetable(rand(5,1),'RowTimes',datetime('now')+sort(hours(rand(5,1))))
tt =
5×1 timetable
Time Var1
____________________ _______
11-Mar-2019 11:11:25 0.81472
11-Mar-2019 11:22:16 0.90579
11-Mar-2019 11:38:23 0.12699
11-Mar-2019 12:03:01 0.91338
11-Mar-2019 12:03:28 0.63236
>> tt.TimeDiff = [NaN; diff(tt.Time)]
tt =
5×2 timetable
Time Var1 TimeDiff
____________________ _______ ________
11-Mar-2019 11:11:25 0.81472 NaN
11-Mar-2019 11:22:16 0.90579 00:10:51
11-Mar-2019 11:38:23 0.12699 00:16:06
11-Mar-2019 12:03:01 0.91338 00:24:38
11-Mar-2019 12:03:28 0.63236 00:00:26
0 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!