필터 지우기
필터 지우기

Add date stamp to time stamp

조회 수: 29 (최근 30일)
vicsm
vicsm 2019년 11월 1일
댓글: vicsm 2019년 11월 1일
Hi,
I have a 270176x15 table (see attached a reduced version of it, called BB.mat) where one of my arrays is Time (with measurements every second). Date stamp is missing, and I have two questions about this:
1) How can I add the date stamp (Date) that changes accordingly to my Time (i.e. changes day from 23:59 to 00:00) IF
2) (IF) the only date reference I have is: my last timestamp (i.e. 16:05:07) corresponds to 21/05/2018? (so basically I know the end date but not the start date).
Does anyone know how to do this? Any help will be very much appreciated!

채택된 답변

Guillaume
Guillaume 2019년 11월 1일
Here's how I'd do it. Whatever you do don't use outdated datenum and datestr. Stay with datetime and duration arrays.
[h, m, s] = hms(HRV_BB3.Time(end)); %extract hours, minutes and seconds from last time (actually a datetime whose date is wrong)
enddate = datetime(2018,5,21,h,m,s) %calculate the right datetime
HRV_BB3.DateTime = enddate + [cumsum(-mod(diff(HRV_BB3.Time), hours(24)), 'reverse'); 0]; %calculate difference between consecutive dates, modulo 24h, and add that back
Done!
This assumes of course that days aren't skipped. But since you've lost that information, there's no way to know.
  댓글 수: 1
vicsm
vicsm 2019년 11월 1일
THANK YOU so much! This solved my problem completely!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 11월 1일
Hi,
these commands will resolve your task:
load BB
EEE=datenum(HRV_BB3.Time);
DATES = datestr(EEE, 'mm/dd/yy');
You'd need to adjust the starting day or end day.
Good luck.
  댓글 수: 3
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 11월 1일
편집: Sulaymon Eshkabilov 2019년 11월 1일
The data you have provided BB.mat works very well. Probably the data (mat file) you are using is different from the one you have provided here - BB.mat
vicsm
vicsm 2019년 11월 1일
편집: vicsm 2019년 11월 1일
But the date doesn't change from 23:59:59 to 00:00:00; it's still 10/30/19 and instead it should be 11/01/19. Maybe I'm not explaining myself properly...
I need it to look like this:
23:59:56 10/30/19
23:59:57 10/30/19
23:59:58 10/30/19
23:59:59 10/30/19
00:00:00 11/01/19
00:00:01 11/01/19
00:00:02 11/01/19

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by