How to convert dates into Julian dates?

7 ビュー (過去 30 日間)
Devendra
Devendra 2024 年 4 月 8 日
コメント済み: James Tursa 2024 年 4 月 8 日
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 件のコメント
Stephen23
Stephen23 2024 年 4 月 8 日
編集済み: Stephen23 2024 年 4 月 8 日
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.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2024 年 4 月 8 日
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 件のコメント
Steven Lord
Steven Lord 2024 年 4 月 8 日
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 2024 年 4 月 8 日
編集済み: Devendra 2024 年 4 月 8 日
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

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2024 年 4 月 8 日
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 件のコメント
Devendra
Devendra 2024 年 4 月 8 日
Thank you very much for your kind help.
Deva
James Tursa
James Tursa 2024 年 4 月 8 日
@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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by