Error using time date table
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Peter Perkins
on 11 Mar 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 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!