How to convert dates into Julian dates?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
jdt = juliandate(gdt) % Julian
댓글 수: 3
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'))
x = 1e-4
V = [J, x] % V(2) _displayed_ as 0
y = V(2) % but it's not actually _stored_ as 0
If so, changing the display format may be sufficient for your needs.
format shortg
V
format longg
V
추가 답변 (1개)
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
days(gdt - datetime(year(gdt),1,1)) + 1 % day of year, with Jan 1 being day number 1
I am aware that some fields of study refer to "day of year" as "Julian Date", but this is incorrect terminology.
댓글 수: 4
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 Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!