Assign date values manually to datetime array matlab
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ganesh Naik
am 8 Apr. 2021
Kommentiert: Ganesh Naik
am 9 Apr. 2021
Hi all, I have this date data (attached) where I need to assign the day numbers (manually) as 1, 2 etc using the starting date (in this example '2021-02-05 05:02:00' as day 1 and '2021-03-07 04:57:00' as say 31). I use Matlab function "day(data)" where it gives me the day numbers based on calender date ('2021-03-07 04:57:00' as day 5). Could you please help me to assign the date manually.
Thanks in advance
Akzeptierte Antwort
Rik
am 8 Apr. 2021
For pre-R2020b, you can use readfile, which you can get readfile from the FEX. If you are using R2017a or later, you can also get it through the AddOn-manager.
date_list=readlines('https://www.mathworks.com/matlabcentral/answers/uploaded_files/576897/Date.txt');
date_list=strrep(date_list,'''','');%remove quotes
date_list=datetime(date_list,'InputFormat','yyyy-MM-dd HH:mm:ss')
day_numbers=days(date_list-min(date_list))+1
You can use round, floor, or ceil if you want round numbers.
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!