How to convert dates into Julian dates?

7 Ansichten (letzte 30 Tage)
Devendra
Devendra am 8 Apr. 2024
Kommentiert: James Tursa am 8 Apr. 2024
I have read the dates in yyyymmdd format as follows;
dates = 20230409 20230414 20230504 20230514 20230519 20230608 20230613 20230723 20230817 20230827 20230901 20231006 20231011 20231026 20231115 20231125 20231205 20231210 20240129
I want to convert these dates into julian dates. Please suggest me how to do it?
I will appreciate your kind cooperation.
Deva
  1 Kommentar
Stephen23
Stephen23 am 8 Apr. 2024
Bearbeitet: Stephen23 am 8 Apr. 2024
Make sure that you import the data as DATETIME, then use:
Do not import dates as scalar numerics whose digits just happen to look like those of some unrelated date units.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 8 Apr. 2024
Assuming your dates are currently stored as a numeric array, then
dates = [20230409 20230414 20230504 20230514 20230519 20230608 20230613 20230723 20230817 20230827 20230901 20231006 20231011 20231026 20231115 20231125 20231205 20231210 20240129];
gdt = datetime(dates,"ConvertFrom","yyyymmdd") % Gregorian
gdt = 1x19 datetime array
Columns 1 through 13 09-Apr-2023 14-Apr-2023 04-May-2023 14-May-2023 19-May-2023 08-Jun-2023 13-Jun-2023 23-Jul-2023 17-Aug-2023 27-Aug-2023 01-Sep-2023 06-Oct-2023 11-Oct-2023 Columns 14 through 19 26-Oct-2023 15-Nov-2023 25-Nov-2023 05-Dec-2023 10-Dec-2023 29-Jan-2024
jdt = juliandate(gdt) % Julian
jdt = 1x19
1.0e+06 * 2.4600 2.4600 2.4601 2.4601 2.4601 2.4601 2.4601 2.4601 2.4602 2.4602 2.4602 2.4602 2.4602 2.4602 2.4603 2.4603 2.4603 2.4603 2.4603
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
See the documentation for juliandate for details on the meaning of that output.
  3 Kommentare
Steven Lord
Steven Lord am 8 Apr. 2024
all other 10 variables becomes zero.
Do those other elements become zero or are they simply displayed as zero because they're much, much smaller than the Julian dates?
J = juliandate(datetime('today'))
J = 2.4604e+06
x = 1e-4
x = 1.0000e-04
V = [J, x] % V(2) _displayed_ as 0
V = 1x2
1.0e+06 * 2.4604 0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y = V(2) % but it's not actually _stored_ as 0
y = 1.0000e-04
If so, changing the display format may be sufficient for your needs.
format shortg
V
V = 1x2
1.0e+00 * 2.4604e+06 0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
format longg
V
V = 1x2
1.0e+00 * 2460408.5 0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Devendra
Devendra am 8 Apr. 2024
Bearbeitet: Devendra am 8 Apr. 2024
Thanks for your kind help. Yes they are displayed as zero because they're much, much smaller than the Julian dates? Yes it displayed all the variables. I appreciate your kind support.
Deva

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

James Tursa
James Tursa am 8 Apr. 2024
Based on your comment that you are expecting numbers in the range of 273,287,298, etc., if what you are after is actually "day of year" and not "Julian Date", then
dates = [20230409 20230414 20230504 20230514 20230519 20230608 20230613 20230723 20230817 20230827 20230901 20231006 20231011 20231026 20231115 20231125 20231205 20231210 20240129];
gdt = datetime(dates,"ConvertFrom","yyyymmdd") % Gregorian
gdt = 1x19 datetime array
Columns 1 through 13 09-Apr-2023 14-Apr-2023 04-May-2023 14-May-2023 19-May-2023 08-Jun-2023 13-Jun-2023 23-Jul-2023 17-Aug-2023 27-Aug-2023 01-Sep-2023 06-Oct-2023 11-Oct-2023 Columns 14 through 19 26-Oct-2023 15-Nov-2023 25-Nov-2023 05-Dec-2023 10-Dec-2023 29-Jan-2024
days(gdt - datetime(year(gdt),1,1)) + 1 % day of year, with Jan 1 being day number 1
ans = 1x19
99 104 124 134 139 159 164 204 229 239 244 279 284 299 319 329 339 344 29
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I am aware that some fields of study refer to "day of year" as "Julian Date", but this is incorrect terminology.
  4 Kommentare
Devendra
Devendra am 8 Apr. 2024
Thank you very much for your kind help.
Deva
James Tursa
James Tursa am 8 Apr. 2024
@Steven Lord I thought I remembered there was a function for this but couldn't find it in datetime methods. Didn't think to look in day( ) doc. Thanks for the update.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Objects finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by