How to convert date by changine date format from text file?
Show older comments
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.
Accepted Answer
More Answers (1)
Himanshu Rai
on 25 Jun 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 Comments
Dogan Deniz Karadeniz
on 25 Jun 2019
Himanshu Rai
on 25 Jun 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
on 25 Jun 2019
Himanshu Rai
on 25 Jun 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
on 25 Jun 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
on 25 Jun 2019
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!