convert Modified Julian Date

조회 수: 10 (최근 30일)
Kate L.
Kate L. 2011년 11월 14일
I am importing a .dat file that has MJD in the form of "55743.21235" and if converted in Excel (by taking the cell-50813) is 06/30/11 05:05:47. This is cummlative file with years worth of data but each quarter, I am only interested in the current quarter(i.e. Oct 01, 2011-Dec 31, 2011).
How can I convert/change each of the MJDs (in a single column of over +1000 MJDs) that I import into the more meaningful form of 'dd:mmm:yyyy' or 'mmm:dd:yyyy'? Once the conversion is complete, the user will be queried to select a time frame, or quarter, of interest. The HH:MM:SS aren't required. Thanks, Kate

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 15일
The difference between datenum('06/30/11 05:05:47') (your proposed translation) and 55743.21235, is 678941
However, datenum('Nov 17, 1858,00:00') is 678942, which is a one day difference compared to your proposal.
The Nov 17, 1858 00:00 date is listed in Wikipedia, and the 678942 offset is exactly that needed to properly convert the example MJD 49987 to September 27, 1995, as documented in the US Naval Observatory web site
The evidence would seem to suggest that your calculations are off by exactly one day, and that Fangjun's calculations are correct.
  댓글 수: 1
Kate L.
Kate L. 2011년 11월 16일
works perfectly...thank you!
mjd = data(1:end,1) %mjd in the form 55743.21235
mjdconv = mjd+678942
datestr(mjdconv)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
You can use datestr(),datenum() and datevec() function. Try this:
a=now;
b=datestr(a)
c=datevec(a)
According to Wikipedia, http://en.wikipedia.org/wiki/Julian_day, the epoch (commencing time) of MJD is 00:00 November 17, 1858, Wednesday. So,
d = 55743.21235;
MJD_epoch='Nov 17, 1858,00:00';
datestr(d+datenum(MJD_epoch))
ans =
01-Jul-2011 05:05:47
I am not sure why it's still off one day (according to you). Are you sure you got the correct day?
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
You mentioned an offset of 50813?
a=55743.21235;
b=a-50813;
datestr(a)
datestr(b)
Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
datestr() and datenum() can specify pivot year too. See the document.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by