필터 지우기
필터 지우기

Excluding date from date and time

조회 수: 80 (최근 30일)
Tea
Tea 2019년 5월 26일
댓글: Peter Perkins 2022년 6월 22일
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
Luis J Gilarranz 2019년 5월 26일
can you post a excerpt of the data?
Tea
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.

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

채택된 답변

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
  댓글 수: 3
Laukik Avinash Kharche
Laukik Avinash Kharche 2022년 6월 22일
Hii All,
I need help in similar kind of situation. My experiment was done from 16:00 to 15:00 uhr next day. The time is extracted by me from excel to matlab and then I use the datetime function to convert to datetime. The time is correctly converted but the date introduced is 31st Dec 2000. I am not sure why is that happening. Even if I try to ignore the date and use the HH:mm:ss.SSS format for the datetime variable, the date 31st Dec is plotted on the Graph which I dont want. Can somebody help ?
Thank you,
Laukik.
Peter Perkins
Peter Perkins 2022년 6월 22일
You should post this as a new question in a new thread, and you need to provide more details.

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

추가 답변 (1개)

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
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.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by