time increment and julian date

4 次查看(过去 30 天)
Hello everyone,
Here is my problem:
First I have a departure date:
date_ = ( 2011 08 18) % initialize
Let's say I have a loop as well, and within this loop I need to convert from calendar date to Julian date since I am using this information later to determine the geocentric position of the Sun rsun_.
For t = 0 : 30 min : 200 days % 200 days is the simulation time
date_ = date_ + t_; % how to add 30 minutes for each iteration and
keeping format (YYYY MM DD) for conversion to
Julian date
date__ = julian( date_ );
rsun_ = ephemeris_sun( date__ );
% after I can perform my calculations
My problem is: look comment in the loop.
Thanks a lot,
Rom

采纳的回答

Laura Proctor
Laura Proctor 2011-7-7
Create the initial date as a 1x6 vector:
od = [ 2011 08 18 0 0 0 ];
Then, to add 30 minutes at each iteration, add 30 to the fifth element:
od(5) = od(5) + 30;
now you can use juliandate to convert the information to a Julian date:
jd = juliandate(od);
  1 个评论
James Tursa
James Tursa 2011-7-9
Side Note: That only works if od is in Ephemeris Time. If od is in UT then it doesn't account for leap seconds. If od is not in UT then it won't account for time zone differences. Don't use this method for precision work.

请先登录,再进行评论。

更多回答(2 个)

James Tursa
James Tursa 2011-7-7
Caution: To be precise, a sun position algorithm will need a Julian Date based on Ephemeris Time. So you would need to convert the date vector from whatever time convention it is in (e.g., your local time, or UT, or whatever) to an Ephemeris Time before doing the Julian Date conversion. Basically, planetary calculations need a continuous time to work with, and local times, UT, etc do not meet that requirement. What time convention is your date vector in?

Argiris
Argiris 2022-8-31
following is a code that increases the time every 10 seconds and has an output a table A=[YY,MM,DD,HH,MM,SS].
You can then easily manipulate the matrix to any spesific form by combining stings and variables.
e.g
A(1)+"/"+A(2)+"/"+A(3)+" "+A(4)+":"+A(5)+":"+A(6)
time= [2022,1,1,0,0,0]; %Initiallize time and date
c=0;
c1=0;
c2=0;
c3=0;
c4=0;
j=0;
time_increment=10; %time increment in seconds
for i=0:65000
if time(6)<=60
time(6)=time(6)+time_increment;
c=c+1;
end
if time(6)>=60
time(6)=0;
time(5)=time(5)+1;
c=0;
c1=c1+1;
end
if time(5)>=60
time(5)=0;
time(4)=time(4)+1;
c1=0;
c2=c1+1;
end
if time(4)>=24
time(4)=0;
time(3)=time(3)+1;
c2=0;
c3=c3+1;
end
if time(3)>=12
time(3)=0;
time(2)=time(2)+1;
c3=0;
c4=c4+1;
end
j=j+1;
A(j,1)=time(1);
A(j,2)=time(2);
A(j,3)=time(3);
A(j,4)=time(4);
A(j,5)=time(5);
A(j,6)=time(6);
end
  1 个评论
Steven Lord
Steven Lord 2022-8-31
Rather than doing the date and time arithmetic yourself, just let datetime handle it.
startTime = datetime(2022,1,1)
startTime = datetime
01-Jan-2022
Let's say that I want ten date and time values spaced 10 minutes apart, starting at startTime.
increments = (0:9).'*minutes(10);
theTimes = startTime + increments
theTimes = 10×1 datetime array
01-Jan-2022 00:00:00 01-Jan-2022 00:10:00 01-Jan-2022 00:20:00 01-Jan-2022 00:30:00 01-Jan-2022 00:40:00 01-Jan-2022 00:50:00 01-Jan-2022 01:00:00 01-Jan-2022 01:10:00 01-Jan-2022 01:20:00 01-Jan-2022 01:30:00
If we wanted Julian dates:
format longg
theJulianDates = juliandate(theTimes)
theJulianDates = 10×1
1.0e+00 * 2459580.5 2459580.50694444 2459580.51388889 2459580.52083333 2459580.52777778 2459580.53472222 2459580.54166667 2459580.54861111 2459580.55555556 2459580.5625

请先登录,再进行评论。

类别

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