MATLAB Answers

Tea
0

Excluding date from date and time

Tea
さんによって質問されました 2019 年 5 月 26 日
最新アクティビティ Peter Perkins
さんによって コメントされました 2019 年 6 月 4 日
Hello,
I am fascing difficulties with plotting data. My data are containg measurements of heart rate. First column is string with date and time, and second column are values of heart rate. I have converted first column into datetime values using following code:
day89 = datenum(heartrate_89.start_time, 'yyyy-mm-dd HH:MM:SS.FFF');
ts2 = day89;
ts2 = datetime(ts2,'TimeZone','local',...
'ConvertFrom','datenum');
day89=ts2
I have measurements for couple of days and since all of them are staring from 20:00 and last till 10:00, I was wondering if there is a way to plot a graph starting from 20:00 untill 10:00, containing traces for couple of days, because when I try to plot different traces on same graph, since the dates are different, they are far away from each other?
Is there a way to completely exclude date value since I am only interested in time?
Thank you

  2 件のコメント

Luis J Gilarranz 2019 年 5 月 26 日
can you post a excerpt of the data?
Tea
2019 年 5 月 26 日
Yes, for example, data are starting from 8th of May (20:00) and finishing on 9th of May (around 10:00), which is one night.
I have couple of nights starting from same time and ending at same time.
I hope this picture will help.

サインイン to comment.

2 件の回答

Rik
回答者: Rik
2019 年 5 月 26 日
 採用された回答

You can probably also do this with the datetime class, but when you still have your time in the datenum format, you can simply subtract the floor to keep only time.
If you want to keep the traces continuous you can add 1 to values befor 10 AM.
day89 = datenum(heartrate_89.start_time, 'yyyy-mm-dd HH:MM:SS.FFF');
%crop to 1 day
day89 = day89-floor(day89);
L= day89 <= 10/24;
day89(L)=day89(L)+1;
ts2 = day89;
ts2 = datetime(ts2,'TimeZone','local',...
'ConvertFrom','datenum');
day89=ts2

  1 件のコメント

Tea
2019 年 5 月 26 日
Thank you, this solved my problem.

サインイン to comment.


the cyclist
回答者: the cyclist
2019 年 5 月 26 日
編集済み: the cyclist
2019 年 5 月 26 日

You should be able to use the timeofday function.
The resulting output will be a duration array.

  1 件のコメント

Peter Perkins
2019 年 6 月 4 日
the cyclist is correct. While Rik's trick works, sort of, it also creates datetimes that are in the (ISO) year -1.
>> dn = now
dn =
7.3758e+05
>> dn0 = dn - floor(dn)
dn0 =
0.39464
>> dt = datetime(dn0,'ConvertFrom','datenum')
dt =
datetime
31-Dec--0001 09:28:17
That will eventually come back to bit you. durations are the way to go.

サインイン to comment.



Translated by