Convert DoY and hour to datetime format
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Benju Baniya
le 1 Juil 2022
Commenté : Benju Baniya
le 1 Juil 2022
I am very new to matlab and I am working with timeseries data. In the attached example, I want to add a new column as Datetime that displays datetime in the format year, month, day, hour, minute (YYYYMMDDHHMM). Your help will be much appreciated. Thanks.
Year DoY Hour Datetime
2013 1 0.5 201301010030
0 commentaires
Réponse acceptée
Abhishek Tiwari
le 1 Juil 2022
Hi,
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1053045/example.xlsx');
T.Datetime = datetime(T.Year, 1, T.DoY, floor(T.Hour), rem(T.Hour, 1).*60, 0, 'format', 'yyyyMMddHHmm')
These might be useful:
Plus de réponses (1)
Eric Sofen
le 1 Juil 2022
The datetime constructor is forgiving about day values that don't fit within a particular month and wrapping them appropriately:
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1053045/example.xlsx")
t.DT = datetime(t.Year,1,t.DoY) + hours(t.Hour)
% Check that it looks reasonable further along...
t(1000:100:end,:)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!