Why doesn't Matlab recognize my data format?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
thanks for reading. My point is that I have a time series from which I want to remove all the 29 of february. My time series is 10 years long.
Now, if I ask Matlab what's the format of my datetime, it replies me with:
ans =
'dd/MM/uuuu'
and, in fact it is correct. But when I ask Matlab to find in my matrix the position of 29 of february I get this error:
Unable to convert the text '29/02/2018' to a datetime value because its
format was not recognized.
Does someone know why?
I specify that I also tried to do table2timetable before running the find function, but it doesn't work.
Thank you!
0 Kommentare
Antworten (2)
Cris LaPierre
am 22 Jun. 2022
Bearbeitet: Cris LaPierre
am 22 Jun. 2022
The error is because 2018 was not a leap year. 2016 and 2020 were.
d1 = '29/02/2016';
datetime(d1)
% The error you see
d2 = '29/02/2018';
datetime(d2)
2 Kommentare
Jan
am 22 Jun. 2022
You have answered this question 30 minutes before?! I did not see your answer before I typed my onw and even not after I sent it. Is it possible that I see the contents with a delay of 30 minutes, when I access the US server of mathworks.com from Europe?
Cris LaPierre
am 22 Jun. 2022
Jan
am 22 Jun. 2022
Bearbeitet: Jan
am 22 Jun. 2022
a = datetime('28/02/2018', 'InputFormat', 'dd/MM/uuuu')
b = datetime('29/02/2018', 'InputFormat', 'dd/MM/uuuu')
% FAILS:
% Unable to convert the text '29/02/2018' to a datetime value because its
% format was not recognized.
There was no Februrary 29th in 2018.
a + days(1) % 01-Mar-2018
A workaround might be the old datenum format:
b = datetime(datevec('29/02/2018', 'dd/mm/yyyy'))
Ugly, but smarter.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!