time increment and julian date
조회 수: 3 (최근 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
댓글 수: 0
채택된 답변
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;
jd = juliandate(od);
댓글 수: 1
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
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?
댓글 수: 0
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
2022년 8월 31일
Rather than doing the date and time arithmetic yourself, just let datetime handle it.
startTime = datetime(2022,1,1)
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
If we wanted Julian dates:
format longg
theJulianDates = juliandate(theTimes)
참고 항목
카테고리
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!