Error using time date table
조회 수: 8 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Peter Perkins
2019년 3월 11일
>> 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!