Excluding date from date and time
101 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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
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
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
2019 年 5 月 26 日
編集済み: the cyclist
2019 年 5 月 26 日
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.
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!