Azzera filtri
Azzera filtri

Excluding date from date and time

80 visualizzazioni (ultimi 30 giorni)
Tea
Tea il 26 Mag 2019
Commentato: Peter Perkins il 22 Giu 2022
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 Commenti
Luis J Gilarranz
Luis J Gilarranz il 26 Mag 2019
can you post a excerpt of the data?
Tea
Tea il 26 Mag 2019
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.

Accedi per commentare.

Risposta accettata

Rik
Rik il 26 Mag 2019
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 Commenti
Laukik Avinash Kharche
Laukik Avinash Kharche il 22 Giu 2022
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 il 22 Giu 2022
You should post this as a new question in a new thread, and you need to provide more details.

Accedi per commentare.

Più risposte (1)

the cyclist
the cyclist il 26 Mag 2019
Modificato: the cyclist il 26 Mag 2019
You should be able to use the timeofday function.
The resulting output will be a duration array.
  1 Commento
Peter Perkins
Peter Perkins il 4 Giu 2019
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.

Accedi per commentare.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by