Converting Date Format to serial date
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Laura
el 25 de Nov. de 2022
Comentada: Star Strider
el 29 de Nov. de 2022
I have a data set ( Sourced originally from NASA, GISS) which includes the date (in what i think is decimal date?!) and the northern hemisphere monthly temperature anomaly. Below is a section of the date:
Date Temp Ann
1880.0000 -0.404500
1880.0834 -0.570571
1880.1666 -0.313143
1880.2500 -0.360071
1880.3334 -0.113643
1880.4166 -0.209643
1880.5000 -0.230857
1880.5834 -0.296357
1880.6666 -0.282214
1880.7500 -0.401439
1880.8334 -0.505396
1880.9166 -0.417626
1881.0000 -0.344500
1881.0834 -0.280571
1881.1666 -0.113143
I need to convert the date into matlab serial date. I've tried datenum which obviously will not work on this format.
In all honesty im not 100% sure what the format actually is.
Any help in recognising the correct format and how to convert it would be greatly appreciated.
0 comentarios
Respuesta aceptada
Star Strider
el 25 de Nov. de 2022
I’m not certain what the decimals are, however they appear to be sequential so they may be fractions of a year.
Unfortunately datetime isn’t set up for years and fraction-of-years, at least not that I can determine. It would be nice to have that option. (I experimented with the ‘epoch’ options, however they produced reults that were obviously wrong.)
A = [1880.0000 -0.404500
1880.0834 -0.570571
1880.1666 -0.313143
1880.2500 -0.360071
1880.3334 -0.113643
1880.4166 -0.209643
1880.5000 -0.230857
1880.5834 -0.296357
1880.6666 -0.282214
1880.7500 -0.401439
1880.8334 -0.505396
1880.9166 -0.417626
1881.0000 -0.344500
1881.0834 -0.280571
1881.1666 -0.113143];
DIY = day(datetime('31-Dec-1880'),'dayofyear') % Leap Year!
DOY = rem(A(:,1),1)*DIY;
HOD = rem(DOY,1)*24;
DT = datetime([fix(A(:,1)) zeros(size(A(:,1)))+1 fix(DOY)+1 fix(HOD) fix(rem(HOD,1)*60) fix(rem(HOD,1)*60)], 'Format','yyyy-MMM-dd HH:mm:ss')
This appears to produce the correct result, although I did not rigorously check it.
NOTE to MathWorks — Would it be possible to implement this as an option?
.
4 comentarios
Star Strider
el 29 de Nov. de 2022
As always, my pleasure!
One note about the precision of the times is that with decimal precison of years:
fprintf('Time Precision = %.2f minutes\n', 366*24*60 * 1E-4)
So the time is essentially in 52.7 minute or 0.878 hour intervals.
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!