How to convert date by changine date format from text file?
Afficher commentaires plus anciens
I'd like to convert date according to first three column as day-month-year hour:minute:second.
- A column: Year
- B column: Day of the year
- C column: Hour
I tried to do it, not achieving.
Réponse acceptée
Plus de réponses (1)
Himanshu Rai
le 25 Juin 2019
Try this function, it accepts three vectors corresponding to year, day and hour
function Dt = conv(Year, Day, Hour)
Dt = datetime(Year, 1, 1) + Day - 1 + hours(Hour);
end
6 commentaires
Dogan Deniz Karadeniz
le 25 Juin 2019
Himanshu Rai
le 25 Juin 2019
You don't have to call this like - conv.
Suppose your data are stored in Year, Day and Hour column vectors, then use the following statement
conv(Year, Day, Hour)
Dogan Deniz Karadeniz
le 25 Juin 2019
Himanshu Rai
le 25 Juin 2019
I will give an example
Year = 2000:2020; % your year vector
Day = 20:40 % your day vector
Hour = 0:20 % your hour vector
conv(Year, Day, Hour) % calling the function with the arguments
Himanshu Rai
le 25 Juin 2019
If you want to read data from the file, use this link - textscan. However note that this was not what was specified in your question. If you want something else please specify it clearly in your question.
Dogan Deniz Karadeniz
le 25 Juin 2019
Catégories
En savoir plus sur Time Series Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!