How to convert date by changine date format from text file?
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (1)
Himanshu Rai
il 25 Giu 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 Commenti
Dogan Deniz Karadeniz
il 25 Giu 2019
Himanshu Rai
il 25 Giu 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
il 25 Giu 2019
Himanshu Rai
il 25 Giu 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
il 25 Giu 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
il 25 Giu 2019
Categorie
Scopri di più su Time Series Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!